Change how plugins are reloaded

This commit is contained in:
Jiiks 2018-01-24 12:35:43 +02:00
parent 1d9e6037d9
commit 87b07d0a0e
7 changed files with 30 additions and 13 deletions

View File

@ -134,16 +134,18 @@ class PluginManager extends Module {
}
}
async loadPlugin(pluginPath) {
async loadPlugin(pluginPath, reload = false, index) {
const { plugins } = this.state;
const dirName = pluginPath;
try {
pluginPath = path.join(this.pluginsPath, pluginPath);
const loaded = plugins.find(plugin => plugin.pluginPath === pluginPath);
if (loaded) {
throw { 'message': 'Attempted to load an already loaded plugin' };
if (!reload) {
const loaded = plugins.find(plugin => plugin.pluginPath === pluginPath);
if (loaded) {
throw { 'message': 'Attempted to load an already loaded plugin' };
}
}
const readConfig = await this.readConfig(pluginPath);
@ -165,8 +167,8 @@ class PluginManager extends Module {
const instance = new plugin({configs, info: readConfig.info, main: readConfig.main, paths: { pluginPath, dirName }});
if (instance.enabled) instance.start();
plugins.push(instance);
if (reload) plugins[index] = instance;
else plugins.push(instance);
this.setState(plugins);
@ -184,9 +186,9 @@ class PluginManager extends Module {
const { pluginPath, dirName } = _plugin;
delete window.require.cache[window.require.resolve(pluginPath)];
this.plugins.splice(index, 1);
// this.plugins.splice(index, 1);
return this.loadPlugin(dirName);
return this.loadPlugin(dirName, true, index);
}
//TODO make this nicer

View File

@ -10,7 +10,7 @@
const components = { MiSettings, Button, ButtonGroup, MiReload, MiEdit, MiDelete };
export default {
props: ['plugin', 'togglePlugin'],
props: ['plugin', 'togglePlugin', 'reloadPlugin'],
components,
name: "PluginCard"
}

View File

@ -35,7 +35,11 @@
}
}
const methods = { showLocal, showOnline, refreshLocalPlugins, togglePlugin };
function reloadPlugin(plugin) {
this.pluginManager.reloadPlugin(plugin.name);
}
const methods = { showLocal, showOnline, refreshLocalPlugins, togglePlugin, reloadPlugin };
export default {
components,

View File

@ -16,7 +16,7 @@
<Button>
<MiSettings/>
</Button>
<Button>
<Button :onClick="() => reloadPlugin(plugin)">
<MiReload/>
</Button>
<Button>

View File

@ -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" :togglePlugin="togglePlugin"/>
<PluginCard v-for="plugin in localPlugins" :plugin="plugin" :key="plugin.id" :togglePlugin="togglePlugin" :reloadPlugin="reloadPlugin"/>
</div>
<div v-if="!local" class="bd-spinner-container">
<div class="bd-spinner-2"></div>

View File

@ -10,6 +10,7 @@
font-weight: 500;
background: $colbdblue;
&:not(.bd-disabled):hover {
background: darken($colbdblue, 5%);
}
@ -46,6 +47,11 @@
.bd-spinner-7 {
opacity: .3;
}
.material-design-icon svg {
width: 18px;
height: 18px;
}
}
.bd-button-group {
@ -99,6 +105,11 @@
display: flex;
align-items: center;
fill: #FFF;
svg {
width: 24px;
height: 24px;
}
}
&:hover {

View File

@ -11,7 +11,7 @@ module.exports = (Plugin, Api, Vendor) => {
}
onStart() {
console.log('On Start!');
console.log('On Start!!!!');
return true;
}
}