You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-06 23:56:13 +02:00
Chore: Apply changes from mobile plugins to lib/
and app-desktop/
(#10079)
This commit is contained in:
@ -144,6 +144,22 @@ export default class PluginService extends BaseService {
|
||||
delete this.plugins_[pluginId];
|
||||
}
|
||||
|
||||
public async unloadPlugin(pluginId: string) {
|
||||
const plugin = this.plugins_[pluginId];
|
||||
if (plugin) {
|
||||
this.logger().info(`Unloading plugin ${pluginId}`);
|
||||
|
||||
plugin.onUnload();
|
||||
await this.runner_.stop(plugin);
|
||||
|
||||
this.deletePluginAt(pluginId);
|
||||
this.startedPlugins_ = { ...this.startedPlugins_ };
|
||||
delete this.startedPlugins_[pluginId];
|
||||
} else {
|
||||
this.logger().info(`Unable to unload plugin ${pluginId} -- already unloaded`);
|
||||
}
|
||||
}
|
||||
|
||||
private async deletePluginFiles(plugin: Plugin) {
|
||||
await shim.fsDriver().remove(plugin.baseDir);
|
||||
}
|
||||
@ -167,7 +183,7 @@ export default class PluginService extends BaseService {
|
||||
return output;
|
||||
}
|
||||
|
||||
public serializePluginSettings(settings: PluginSettings): any {
|
||||
public serializePluginSettings(settings: PluginSettings): string {
|
||||
return JSON.stringify(settings);
|
||||
}
|
||||
|
||||
@ -343,7 +359,7 @@ export default class PluginService extends BaseService {
|
||||
|
||||
private pluginEnabled(settings: PluginSettings, pluginId: string): boolean {
|
||||
if (!settings[pluginId]) return true;
|
||||
return settings[pluginId].enabled !== false;
|
||||
return settings[pluginId].enabled !== false && settings[pluginId].deleted !== true;
|
||||
}
|
||||
|
||||
public callStatsSummary(pluginId: string, duration: number) {
|
||||
@ -407,6 +423,20 @@ export default class PluginService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
public async loadAndRunDevPlugins(settings: PluginSettings) {
|
||||
const devPluginOptions = { devMode: true, builtIn: false };
|
||||
|
||||
if (Setting.value('plugins.devPluginPaths')) {
|
||||
const paths = Setting.value('plugins.devPluginPaths').split(',').map((p: string) => p.trim());
|
||||
await this.loadAndRunPlugins(paths, settings, devPluginOptions);
|
||||
}
|
||||
|
||||
// Also load dev plugins that have passed via command line arguments
|
||||
if (Setting.value('startupDevPlugins')) {
|
||||
await this.loadAndRunPlugins(Setting.value('startupDevPlugins'), settings, devPluginOptions);
|
||||
}
|
||||
}
|
||||
|
||||
public isCompatible(pluginVersion: string): boolean {
|
||||
return compareVersions(this.appVersion_, pluginVersion) >= 0;
|
||||
}
|
||||
@ -450,6 +480,7 @@ export default class PluginService extends BaseService {
|
||||
public async installPluginFromRepo(repoApi: RepositoryApi, pluginId: string): Promise<Plugin> {
|
||||
const pluginPath = await repoApi.downloadPlugin(pluginId);
|
||||
const plugin = await this.installPlugin(pluginPath);
|
||||
|
||||
await shim.fsDriver().remove(pluginPath);
|
||||
return plugin;
|
||||
}
|
||||
@ -467,6 +498,13 @@ export default class PluginService extends BaseService {
|
||||
const preloadedPlugin = await this.loadPluginFromPath(jplPath);
|
||||
await this.deletePluginFiles(preloadedPlugin);
|
||||
|
||||
// On mobile, it's necessary to create the plugin directory before we can copy
|
||||
// into it.
|
||||
if (!(await shim.fsDriver().exists(Setting.value('pluginDir')))) {
|
||||
logger.info(`Creating plugin directory: ${Setting.value('pluginDir')}`);
|
||||
await shim.fsDriver().mkdir(Setting.value('pluginDir'));
|
||||
}
|
||||
|
||||
const destPath = `${Setting.value('pluginDir')}/${preloadedPlugin.id}.jpl`;
|
||||
await shim.fsDriver().copy(jplPath, destPath);
|
||||
|
||||
|
Reference in New Issue
Block a user