diff --git a/client/src/modules/contentmanager.js b/client/src/modules/contentmanager.js index b5576d4d..934a4c62 100644 --- a/client/src/modules/contentmanager.js +++ b/client/src/modules/contentmanager.js @@ -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); diff --git a/client/src/modules/pluginmanager.js b/client/src/modules/pluginmanager.js index 6182153f..fc7b2246 100644 --- a/client/src/modules/pluginmanager.js +++ b/client/src/modules/pluginmanager.js @@ -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 } diff --git a/client/src/ui/components/bd/PluginsView.vue b/client/src/ui/components/bd/PluginsView.vue index a3f19cea..85566565 100644 --- a/client/src/ui/components/bd/PluginsView.vue +++ b/client/src/ui/components/bd/PluginsView.vue @@ -71,7 +71,16 @@ }, refreshLocal() { }, togglePlugin() { }, - reloadPlugin() { }, + reloadPlugin(plugin) { + (async () => { + try { + await this.pluginManager.reloadPlugin(plugin); + this.$forceUpdate(); + } catch (err) { + console.log(err); + } + })(); + }, showSettings() { } } }