Plugin reloading

This commit is contained in:
Jiiks 2018-01-31 10:17:15 +02:00
parent 1896a0d558
commit e0df52b6ab
3 changed files with 25 additions and 3 deletions

View File

@ -116,14 +116,15 @@ export default class {
}
const content = await this.loadContent(paths, configs, readConfig.info, readConfig.main);
this.localContent.push(content);
if (reload) this.localContent[index] = content;
else this.localContent.push(content);
return content;
} catch (err) {
throw err;
}
}
static async readConfig(configPath) {
configPath = path.resolve(configPath, 'config.json');
return FileUtils.readJsonFromFile(configPath);

View File

@ -52,6 +52,18 @@ export default class extends ContentManager {
}
}
static async reloadPlugin(plugin) {
const _plugin = plugin instanceof Plugin ? plugin : this.findPlugin(plugin);
if (!_plugin) throw { 'message': 'Attempted to reload a plugin that is not loaded?' };
if (!_plugin.stop()) throw { 'message': 'Plugin failed to stop!' };
const index = this.getPluginIndex(_plugin);
const { pluginPath, dirName } = _plugin;
delete window.require.cache[window.require.resolve(pluginPath)];
return this.preloadContent(dirName, true, index);
}
static get findPlugin() { return this.findContent }
static get getPluginIndex() { return this.getContentIndex }
static get getPluginByName() { return this.getContentByName }

View File

@ -71,7 +71,16 @@
},
refreshLocal() { },
togglePlugin() { },
reloadPlugin() { },
reloadPlugin(plugin) {
(async () => {
try {
await this.pluginManager.reloadPlugin(plugin);
this.$forceUpdate();
} catch (err) {
console.log(err);
}
})();
},
showSettings() { }
}
}