diff --git a/client/src/modules/core/pluginmanager.js b/client/src/modules/core/pluginmanager.js index 9ad77634..03ba7ad8 100644 --- a/client/src/modules/core/pluginmanager.js +++ b/client/src/modules/core/pluginmanager.js @@ -17,6 +17,8 @@ class Plugin { constructor(pluginInternals) { this.__pluginInternals = pluginInternals; + this.start = this.start.bind(this); + this.stop = this.stop.bind(this); } get configs() { return this.__pluginInternals.configs } @@ -33,12 +35,25 @@ class Plugin { get enabled() { return this.userConfig.enabled } start() { - if (this.onStart) return this.onStart(); + if (this.onStart) { + const started = this.onStart(); + if (started) { + return this.userConfig.enabled = true; + } + return false; + } return true; //Assume plugin started since it doesn't have onStart } stop() { - if (this.onStop) return this.onStop(); + if (this.onStop) { + const stopped = this.onStop(); + if (stopped) { + this.userConfig.enabled = false; + return true; + } + return false; + } return true; //Assume plugin stopped since it doesn't have onStop } @@ -192,7 +207,7 @@ class PluginManager extends Module { stopPlugin(name) { const plugin = this.getPluginByName(name); try { - if (plugin && plugin.instance) return plugin.instance.stop(); + if (plugin) return plugin.stop(); } catch (err) { Logger.err('PluginManager', err); } @@ -202,7 +217,7 @@ class PluginManager extends Module { startPlugin(name) { const plugin = this.getPluginByName(name); try { - if (plugin && plugin.instance) return plugin.instance.start(); + if (plugin) return plugin.start(); } catch (err) { Logger.err('PluginManager', err); } diff --git a/client/src/modules/ui/components/bd/PluginCard.vue b/client/src/modules/ui/components/bd/PluginCard.vue index 098d8b4b..b17f57a7 100644 --- a/client/src/modules/ui/components/bd/PluginCard.vue +++ b/client/src/modules/ui/components/bd/PluginCard.vue @@ -1,9 +1,8 @@ \ No newline at end of file diff --git a/client/src/modules/ui/components/bd/PluginsView.vue b/client/src/modules/ui/components/bd/PluginsView.vue index eaab8bce..76d17aca 100644 --- a/client/src/modules/ui/components/bd/PluginsView.vue +++ b/client/src/modules/ui/components/bd/PluginsView.vue @@ -28,7 +28,12 @@ this.local = false; } - const methods = { showLocal, showOnline, refreshLocalPlugins }; + function togglePlugin(plugin) { + if (plugin.enabled) return PluginManager.stopPlugin(plugin.name); + PluginManager.startPlugin(plugin.name); + } + + const methods = { showLocal, showOnline, refreshLocalPlugins, togglePlugin }; export default { components, diff --git a/client/src/modules/ui/components/bd/templates/PluginCard.html b/client/src/modules/ui/components/bd/templates/PluginCard.html index bf448e2a..fe461549 100644 --- a/client/src/modules/ui/components/bd/templates/PluginCard.html +++ b/client/src/modules/ui/components/bd/templates/PluginCard.html @@ -2,9 +2,9 @@