diff --git a/client/src/modules/core/pluginmanager.js b/client/src/modules/core/pluginmanager.js index 881f26b2..2f0be7c3 100644 --- a/client/src/modules/core/pluginmanager.js +++ b/client/src/modules/core/pluginmanager.js @@ -17,7 +17,6 @@ class Plugin { constructor(pluginInternals) { this.__pluginInternals = pluginInternals; - this.userConfig.enabled = this.userConfig.enabled || false; this.start = this.start.bind(this); this.stop = this.stop.bind(this); } @@ -34,6 +33,7 @@ class Plugin { get pluginPath() { return this.paths.pluginPath } get dirName() { return this.paths.dirName } get enabled() { return this.userConfig.enabled } + get pluginConfig() { return this.userConfig.pluginConfig } start() { if (this.onStart) { @@ -134,26 +134,35 @@ 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); const mainPath = path.join(pluginPath, readConfig.main); const userConfigPath = path.join(pluginPath, 'user.config.json'); - let userConfig = readConfig.defaultConfig; + const userConfig = { + enabled: false, + pluginConfig: readConfig.defaultConfig + }; try { const readUserConfig = await FileUtils.readJsonFromFile(userConfigPath); - userConfig = Object.assign({}, userConfig, readUserConfig); + //userConfig = Object.assign({}, userConfig, readUserConfig); + userConfig.pluginConfig = readConfig.defaultConfig.map(config => { + const userSet = readUserConfig.pluginConfig.find(c => c.id === config.id); + return userSet || config; + }); } catch (err) {/*We don't care if this fails it either means that user config doesn't exist or there's something wrong with it so we revert to default config*/} const configs = { @@ -165,8 +174,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); @@ -177,16 +186,16 @@ class PluginManager extends Module { } async reloadPlugin(plugin) { - const _plugin = this.findPlugin(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)]; - this.plugins.splice(index, 1); + // this.plugins.splice(index, 1); - return this.loadPlugin(dirName); + return this.loadPlugin(dirName, true, index); } //TODO make this nicer @@ -207,7 +216,7 @@ class PluginManager extends Module { getPluginByDirName(dirName) { return this.plugins.find(p => p.dirName === dirName) } stopPlugin(name) { - const plugin = this.getPluginByName(name); + const plugin = name instanceof Plugin ? name : this.getPluginByName(name); try { if (plugin) return plugin.stop(); } catch (err) { @@ -217,7 +226,7 @@ class PluginManager extends Module { } startPlugin(name) { - const plugin = this.getPluginByName(name); + const plugin = name instanceof Plugin ? name : this.getPluginByName(name); try { if (plugin) return plugin.start(); } catch (err) { @@ -259,4 +268,4 @@ async function pluginManager(pluginName) { if (window.bdTests) window.bdTests.pluginManager = pluginManager; else window.bdTests = { pluginManager }; -module.exports = { PluginManager: _instance } \ No newline at end of file +module.exports = { PluginManager: _instance, Plugin } \ No newline at end of file diff --git a/client/src/modules/index.js b/client/src/modules/index.js index 76422440..5067ecda 100644 --- a/client/src/modules/index.js +++ b/client/src/modules/index.js @@ -1,6 +1,6 @@ export { Global } from './core/global'; export { Logger, Utils, FileUtils } from './core/utils'; -export { PluginManager } from './core/pluginmanager'; +export { PluginManager, Plugin } from './core/pluginmanager'; export { Pluging } from './core/plugin'; export { BDIpc } from './core/bdipc'; export { WebpackModules } from './core/webpackmodules'; diff --git a/client/src/modules/ui/components/BdSettings.vue b/client/src/modules/ui/components/BdSettings.vue index 83532d78..e6587a78 100644 --- a/client/src/modules/ui/components/BdSettings.vue +++ b/client/src/modules/ui/components/BdSettings.vue @@ -93,4 +93,4 @@ this.sidebarItems.forEach(item => item.active = false); } } - + \ No newline at end of file diff --git a/client/src/modules/ui/components/bd/PluginCard.vue b/client/src/modules/ui/components/bd/PluginCard.vue index b17f57a7..9d1841c6 100644 --- a/client/src/modules/ui/components/bd/PluginCard.vue +++ b/client/src/modules/ui/components/bd/PluginCard.vue @@ -1,8 +1,29 @@ \ 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 db9f937d..03a62cf9 100644 --- a/client/src/modules/ui/components/bd/PluginsView.vue +++ b/client/src/modules/ui/components/bd/PluginsView.vue @@ -1,12 +1,13 @@ + \ No newline at end of file diff --git a/client/src/modules/ui/components/bd/templates/PluginCard.html b/client/src/modules/ui/components/bd/templates/PluginCard.html index fe461549..9bd5c75a 100644 --- a/client/src/modules/ui/components/bd/templates/PluginCard.html +++ b/client/src/modules/ui/components/bd/templates/PluginCard.html @@ -7,11 +7,28 @@
+
{{plugin.description}}
+ \ No newline at end of file diff --git a/client/src/modules/ui/components/bd/templates/PluginsView.html b/client/src/modules/ui/components/bd/templates/PluginsView.html index 8085fdd3..ba7b5bb4 100644 --- a/client/src/modules/ui/components/bd/templates/PluginsView.html +++ b/client/src/modules/ui/components/bd/templates/PluginsView.html @@ -1,10 +1,11 @@ +
-
+

Local

- +
@@ -15,10 +16,34 @@
- +
+
+
+ +
+
+
+
+

{{setting.text}}

+
+
+
+ +
+ +
+
+ +
\ No newline at end of file diff --git a/client/src/modules/ui/components/generic/Button.vue b/client/src/modules/ui/components/generic/Button.vue index e69de29b..154ecbe7 100644 --- a/client/src/modules/ui/components/generic/Button.vue +++ b/client/src/modules/ui/components/generic/Button.vue @@ -0,0 +1,11 @@ + + \ No newline at end of file diff --git a/client/src/modules/ui/components/generic/ButtonGroup.vue b/client/src/modules/ui/components/generic/ButtonGroup.vue new file mode 100644 index 00000000..b7d427f6 --- /dev/null +++ b/client/src/modules/ui/components/generic/ButtonGroup.vue @@ -0,0 +1,9 @@ + + \ No newline at end of file diff --git a/client/src/modules/ui/components/generic/Modal.vue b/client/src/modules/ui/components/generic/Modal.vue new file mode 100644 index 00000000..326a7f45 --- /dev/null +++ b/client/src/modules/ui/components/generic/Modal.vue @@ -0,0 +1,24 @@ + + + \ No newline at end of file diff --git a/client/src/modules/ui/components/generic/SettingSwitch.vue b/client/src/modules/ui/components/generic/SettingSwitch.vue index c14db968..28aa91a0 100644 --- a/client/src/modules/ui/components/generic/SettingSwitch.vue +++ b/client/src/modules/ui/components/generic/SettingSwitch.vue @@ -4,7 +4,7 @@

{{setting.title || setting.text}}