From 15f683d4c9f52050df1b3d26362eed85a0d79215 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Mon, 12 Feb 2018 15:20:27 +0000 Subject: [PATCH] Fix Plugin.getSetting --- client/src/modules/plugin.js | 10 ++++++++-- tests/plugins/Example/index.js | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/client/src/modules/plugin.js b/client/src/modules/plugin.js index b78cb5fb..732303c5 100644 --- a/client/src/modules/plugin.js +++ b/client/src/modules/plugin.js @@ -35,8 +35,14 @@ export default class { get enabled() { return this.userConfig.enabled } get pluginConfig() { return this.userConfig.config } - getSetting(settingId) { - return this.userConfig.config.find(setting => setting.id === settingId); + getSetting(setting_id, category_id) { + for (let category of this.pluginConfig) { + if (category_id && category.category !== category_id) return; + for (let setting of category.settings) { + if (setting.id !== setting_id) return; + return setting.value; + } + } } async saveSettings(newSettings) { diff --git a/tests/plugins/Example/index.js b/tests/plugins/Example/index.js index 49110781..a3088ae9 100644 --- a/tests/plugins/Example/index.js +++ b/tests/plugins/Example/index.js @@ -2,11 +2,12 @@ module.exports = (Plugin, Api, Vendor) => { const { $, moment, _ } = Vendor; const { Events, Logger } = Api; - return class extends Plugin { + return class extends Plugin { onStart() { Events.subscribe('TEST_EVENT', this.eventTest); Logger.log('onStart'); + Logger.log(`Setting "default-0" value: ${this.getSetting('default-0')}`); return true; } @@ -19,6 +20,16 @@ module.exports = (Plugin, Api, Vendor) => { eventTest(e) { Logger.log(e); } + + settingChanged(category, setting_id, value) { + if (!this.enabled) return; + Logger.log(`${category}/${setting_id} changed to ${value}`); + } + + settingsChanged(settings) { + if (!this.enabled) return; + Logger.log([ 'Settings updated', settings ]); + } } -} \ No newline at end of file +}