Fix plugin start/stop
This commit is contained in:
parent
e9b15a33b1
commit
19b88b4be0
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
<template src="./templates/PluginCard.html"></template>
|
||||
|
||||
<script>
|
||||
|
||||
export default {
|
||||
props: ['plugin'],
|
||||
props: ['plugin', 'togglePlugin'],
|
||||
name: "PluginCard"
|
||||
}
|
||||
</script>
|
|
@ -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,
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
<div class="bd-plugin-header">
|
||||
<span>{{plugin.name}}</span>
|
||||
<div class="bd-flex-spacer"/>
|
||||
<label class="bd-switch-wrapper">
|
||||
<label class="bd-switch-wrapper" @click="togglePlugin(plugin)">
|
||||
<input type="checkbox" class="bd-switch-checkbox" />
|
||||
<div class="bd-switch"/>
|
||||
<div class="bd-switch" :class="{'bd-checked': plugin.enabled}" />
|
||||
</label>
|
||||
</div>
|
||||
<div class="bd-plugin-body">
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div v-if="local" class="bd-flex bd-flex-grow bd-flex-col bd-plugins-container bd-local-plugins">
|
||||
<PluginCard v-for="plugin in localPlugins" :plugin="plugin" :key="plugin.id"/>
|
||||
<PluginCard v-for="plugin in localPlugins" :plugin="plugin" :key="plugin.id" :togglePlugin="togglePlugin"/>
|
||||
</div>
|
||||
<div v-if="!local" class="bd-spinner-container">
|
||||
<div class="bd-spinner-2"></div>
|
||||
|
|
|
@ -12,6 +12,7 @@ module.exports = (Plugin, Api, Vendor) => {
|
|||
|
||||
onStart() {
|
||||
console.log('On Start!');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ module.exports = (Plugin, Api, Vendor) => {
|
|||
|
||||
onStart() {
|
||||
console.log('On Start!');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue