From 6b96bdbc3b00e3a07addede7c7dc690e27eaf673 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Wed, 14 Feb 2018 01:37:47 +0000 Subject: [PATCH 01/11] Add category names --- client/src/data/user.settings.default.json | 3 ++- client/src/ui/components/bd/SettingsPanel.vue | 4 ++-- tests/plugins/Example/config.json | 8 +++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/client/src/data/user.settings.default.json b/client/src/data/user.settings.default.json index f388baf9..8d9b89a1 100644 --- a/client/src/data/user.settings.default.json +++ b/client/src/data/user.settings.default.json @@ -34,7 +34,8 @@ ] }, { - "category": "Advanced", + "category": "advanced", + "category_name": "Advanced", "type": "drawer", "settings": [ { diff --git a/client/src/ui/components/bd/SettingsPanel.vue b/client/src/ui/components/bd/SettingsPanel.vue index db52c33b..2ed3b8f8 100644 --- a/client/src/ui/components/bd/SettingsPanel.vue +++ b/client/src/ui/components/bd/SettingsPanel.vue @@ -16,11 +16,11 @@
- {{category.category}} static with header + {{ category.category_name }}
- +
diff --git a/tests/plugins/Example/config.json b/tests/plugins/Example/config.json index ee96edbe..fb173c23 100644 --- a/tests/plugins/Example/config.json +++ b/tests/plugins/Example/config.json @@ -8,7 +8,7 @@ "icon": "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iQ2FscXVlXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMjAwMCAyMDAwIiBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMCAyMDAwIDIwMDAiIHhtbDpzcGFjZT0icHJlc2VydmUiPjxnPjxwYXRoIGZpbGw9IiMzRTgyRTUiIGQ9Ik0xNDAyLjIsNjMxLjdjLTkuNy0zNTMuNC0yODYuMi00OTYtNjQyLjYtNDk2SDY4LjR2NzE0LjFsNDQyLDM5OFY0OTAuN2gyNTdjMjc0LjUsMCwyNzQuNSwzNDQuOSwwLDM0NC45SDU5Ny42djMyOS41aDE2OS44YzI3NC41LDAsMjc0LjUsMzQ0LjgsMCwzNDQuOGgtNjk5djM1NC45aDY5MS4yYzM1Ni4zLDAsNjMyLjgtMTQyLjYsNjQyLjYtNDk2YzAtMTYyLjYtNDQuNS0yODQuMS0xMjIuOS0zNjguNkMxMzU3LjcsOTE1LjgsMTQwMi4yLDc5NC4zLDE0MDIuMiw2MzEuN3oiLz48cGF0aCBmaWxsPSIjRkZGRkZGIiBkPSJNMTI2Mi41LDEzNS4yTDEyNjIuNSwxMzUuMmwtNzYuOCwwYzI2LjYsMTMuMyw1MS43LDI4LjEsNzUsNDQuM2M3MC43LDQ5LjEsMTI2LjEsMTExLjUsMTY0LjYsMTg1LjNjMzkuOSw3Ni42LDYxLjUsMTY1LjYsNjQuMywyNjQuNmwwLDEuMnYxLjJjMCwxNDEuMSwwLDU5Ni4xLDAsNzM3LjF2MS4ybDAsMS4yYy0yLjcsOTktMjQuMywxODgtNjQuMywyNjQuNmMtMzguNSw3My44LTkzLjgsMTM2LjItMTY0LjYsMTg1LjNjLTIyLjYsMTUuNy00Ni45LDMwLjEtNzIuNiw0My4xaDcyLjVjMzQ2LjIsMS45LDY3MS0xNzEuMiw2NzEtNTY3LjlWNzE2LjdDMTkzMy41LDMxMi4yLDE2MDguNywxMzUuMiwxMjYyLjUsMTM1LjJ6Ii8+PC9nPjwvc3ZnPg==" }, "main": "index.js", - "type": "plugin", + "type": "plugin", "defaultConfig": [ { "category_default_comment": "default category has no header and is always displayed first", @@ -122,7 +122,8 @@ }, { "category_header_comment": "Setting a category other than default has a header with category name as the text", - "category": "Test Category", + "category": "test-category", + "category_name": "Test Category", "drawer_type_comment": "// Drawer type will create an expandable drawer for the settings", "type": "drawer", "settings": [ @@ -150,7 +151,8 @@ ] }, { - "category": "Test Category 2", + "category": "test-category-2", + "category_name": "Test Category 2 (static with header)", "static_type_comment": "Static type will behave like default but will have a header", "type": "static", "settings": [ From 4b9084bee49d3ee9660c0dec29c7fa10b8b939f5 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Wed, 14 Feb 2018 01:40:47 +0000 Subject: [PATCH 02/11] Add generic settings modal and recursive compare --- client/src/modules/plugin.js | 21 ++-- client/src/styles/partials/modals/index.scss | 1 + .../partials/modals/settings-modal.scss | 32 +++++ client/src/ui/components/bd/BdModals.vue | 1 - .../ui/components/bd/modals/SettingsModal.vue | 114 ++++++++++++++++++ client/src/ui/modals.js | 28 ++++- common/modules/utils.js | 21 ++++ 7 files changed, 208 insertions(+), 10 deletions(-) create mode 100644 client/src/styles/partials/modals/settings-modal.scss create mode 100644 client/src/ui/components/bd/modals/SettingsModal.vue diff --git a/client/src/modules/plugin.js b/client/src/modules/plugin.js index 9ce047fd..1ebcffaa 100644 --- a/client/src/modules/plugin.js +++ b/client/src/modules/plugin.js @@ -8,7 +8,7 @@ * LICENSE file in the root directory of this source tree. */ -import { FileUtils } from 'common'; +import { Utils, FileUtils } from 'common'; import { Modals } from 'ui'; export default class Plugin { @@ -54,13 +54,18 @@ export default class Plugin { } async saveSettings(newSettings) { - for (let category of newSettings) { - const oldCategory = this.pluginConfig.find(c => c.category === category.category); - for (let setting of category.settings) { - const oldSetting = oldCategory.settings.find(s => s.id === setting.id); - if (oldSetting.value === setting.value) continue; - oldSetting.value = setting.value; - if (this.settingChanged) this.settingChanged(category.category, setting.id, setting.value); + const updatedSettings = []; + + for (let newCategory of newSettings) { + const category = this.pluginConfig.find(c => c.category === newCategory.category); + for (let newSetting of newCategory.settings) { + const setting = category.settings.find(s => s.id === newSetting.id); + if (Utils.compare(setting.value, newSetting.value)) continue; + + let old_value = setting.value; + setting.value = newSetting.value; + updatedSettings.push({ category_id: category.category, setting_id: setting.id, value: setting.value, old_value }); + this.settingUpdated(category.category, setting.id, setting.value, old_value); } } diff --git a/client/src/styles/partials/modals/index.scss b/client/src/styles/partials/modals/index.scss index e36ebd94..db8ff474 100644 --- a/client/src/styles/partials/modals/index.scss +++ b/client/src/styles/partials/modals/index.scss @@ -5,3 +5,4 @@ @import './basic-modal.scss'; @import './error-modal.scss'; +@import './settings-modal.scss'; diff --git a/client/src/styles/partials/modals/settings-modal.scss b/client/src/styles/partials/modals/settings-modal.scss new file mode 100644 index 00000000..fd3513a8 --- /dev/null +++ b/client/src/styles/partials/modals/settings-modal.scss @@ -0,0 +1,32 @@ +.bd-settings-modal { + .bd-modal .bd-modal-body { + padding: 0; + } + + .bd-modal .bd-modal-footer { + .bd-ok { + width: 100px; + } + } + + .bd-settings-modal-body { + padding: 0 15px; + margin: 0 0 74px; + + .bd-switch-wrapper { + width: 40px; + height: 20px; + + .bd-switch::before { + width: 14px; + height: 14px; + } + } + } + + &.bd-edited { + .bd-scroller::-webkit-scrollbar-track { + margin-bottom: 74px; + } + } +} diff --git a/client/src/ui/components/bd/BdModals.vue b/client/src/ui/components/bd/BdModals.vue index 34a4bed8..f6216014 100644 --- a/client/src/ui/components/bd/BdModals.vue +++ b/client/src/ui/components/bd/BdModals.vue @@ -38,7 +38,6 @@ }; }, created() { - console.log(this); Events.on('bd-refresh-modals', this.eventListener = () => { this.$forceUpdate(); }); diff --git a/client/src/ui/components/bd/modals/SettingsModal.vue b/client/src/ui/components/bd/modals/SettingsModal.vue new file mode 100644 index 00000000..bdb69688 --- /dev/null +++ b/client/src/ui/components/bd/modals/SettingsModal.vue @@ -0,0 +1,114 @@ +/** + * BetterDiscord Settings Modal Component + * Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks + * All rights reserved. + * https://betterdiscord.net + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. +*/ + + + diff --git a/client/src/ui/modals.js b/client/src/ui/modals.js index fffab1d1..655571b1 100644 --- a/client/src/ui/modals.js +++ b/client/src/ui/modals.js @@ -8,12 +8,13 @@ * LICENSE file in the root directory of this source tree. */ -import { FileUtils } from 'common'; +import { Utils, FileUtils } from 'common'; import { Events, PluginManager, ThemeManager } from 'modules'; import BasicModal from './components/bd/modals/BasicModal.vue'; import ErrorModal from './components/bd/modals/ErrorModal.vue'; import PluginSettingsModal from './components/bd/modals/PluginSettingsModal.vue'; import ThemeSettingsModal from './components/bd/modals/ThemeSettingsModal.vue'; +import SettingsModal from './components/bd/modals/SettingsModal.vue'; export default class { @@ -78,6 +79,31 @@ export default class { }); } + static settings(headertext, settings, settingsUpdated, settingUpdated, saveSettings) { + return this.add({ + headertext, settings, + saveSettings: saveSettings ? saveSettings : newSettings => { + const updatedSettings = []; + + for (let newCategory of newSettings) { + let category = settings.find(c => c.category === newCategory.category); + + for (let newSetting of newCategory.settings) { + let setting = category.settings.find(s => s.id === newSetting.id); + if (Utils.compare(setting.value, newSetting.value)) continue; + + let old_value = setting.value; + setting.value = newSetting.value; + updatedSettings.push({ category_id: category.category, setting_id: setting.id, value: setting.value, old_value }); + if (settingUpdated) settingUpdated(category.category, setting.id, setting.value, old_value); + } + } + + return settingsUpdated ? settingsUpdated(updatedSettings) : updatedSettings; + } + }, SettingsModal); + } + static pluginSettings(plugin) { return this.add({ plugin }, PluginSettingsModal); } diff --git a/common/modules/utils.js b/common/modules/utils.js index 84380086..13f2c7f7 100644 --- a/common/modules/utils.js +++ b/common/modules/utils.js @@ -45,6 +45,27 @@ export class Utils { }); return camelCased; } + + static compare(value1, value2) { + // Check to see if value1 and value2 contain the same data + if (typeof value1 !== typeof value2) return false; + if (value1 === null && value2 === null) return true; + if (value1 === null || value2 === null) return false; + + if (typeof value1 === 'object' || typeof value1 === 'array') { + // Loop through the object and check if everything's the same + let value1array = typeof value1 === 'array' ? value1 : Object.keys(value1); + let value2array = typeof value2 === 'array' ? value2 : Object.keys(value2); + if (value1array.length !== value2array.length) return false; + + for (let key in value1) { + if (!this.compare(value1[key], value2[key])) return false; + } + } else if (value1 !== value2) return false; + + // value1 and value2 contain the same data + return true; + } } export class FileUtils { From f13726d8e28fe0d0bf0b166c0440d1b244fd13a7 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Wed, 14 Feb 2018 01:42:10 +0000 Subject: [PATCH 03/11] Remove old settings modals --- .../src/styles/partials/bdsettings/index.scss | 1 - .../bdsettings/plugin-settings-modal.scss | 32 ----- .../bd/modals/PluginSettingsModal.vue | 117 ------------------ .../bd/modals/ThemeSettingsModal.vue | 117 ------------------ client/src/ui/modals.js | 8 +- 5 files changed, 4 insertions(+), 271 deletions(-) delete mode 100644 client/src/styles/partials/bdsettings/plugin-settings-modal.scss delete mode 100644 client/src/ui/components/bd/modals/PluginSettingsModal.vue delete mode 100644 client/src/ui/components/bd/modals/ThemeSettingsModal.vue diff --git a/client/src/styles/partials/bdsettings/index.scss b/client/src/styles/partials/bdsettings/index.scss index bff6541a..9b482385 100644 --- a/client/src/styles/partials/bdsettings/index.scss +++ b/client/src/styles/partials/bdsettings/index.scss @@ -3,4 +3,3 @@ @import './plugins.scss'; @import './card.scss'; @import './tooltips.scss'; -@import './plugin-settings-modal.scss'; diff --git a/client/src/styles/partials/bdsettings/plugin-settings-modal.scss b/client/src/styles/partials/bdsettings/plugin-settings-modal.scss deleted file mode 100644 index fd423cb0..00000000 --- a/client/src/styles/partials/bdsettings/plugin-settings-modal.scss +++ /dev/null @@ -1,32 +0,0 @@ -.bd-plugin-settings-modal { - .bd-modal .bd-modal-body { - padding: 0; - } - - .bd-modal .bd-modal-footer { - .bd-ok { - width: 100px; - } - } - - .bd-plugin-settings-body { - padding: 0 15px; - margin: 0 0 74px; - - .bd-switch-wrapper { - width: 40px; - height: 20px; - - .bd-switch::before { - width: 14px; - height: 14px; - } - } - } - - &.bd-edited { - .bd-scroller::-webkit-scrollbar-track { - margin-bottom: 74px; - } - } -} diff --git a/client/src/ui/components/bd/modals/PluginSettingsModal.vue b/client/src/ui/components/bd/modals/PluginSettingsModal.vue deleted file mode 100644 index 779ce746..00000000 --- a/client/src/ui/components/bd/modals/PluginSettingsModal.vue +++ /dev/null @@ -1,117 +0,0 @@ -/** - * BetterDiscord Plugin Settings Modal Component - * Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks - * All rights reserved. - * https://betterdiscord.net - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. -*/ - - - diff --git a/client/src/ui/components/bd/modals/ThemeSettingsModal.vue b/client/src/ui/components/bd/modals/ThemeSettingsModal.vue deleted file mode 100644 index b2d693aa..00000000 --- a/client/src/ui/components/bd/modals/ThemeSettingsModal.vue +++ /dev/null @@ -1,117 +0,0 @@ -/** - * BetterDiscord Theme Settings Modal Component - * Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks - * All rights reserved. - * https://betterdiscord.net - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. -*/ - - - diff --git a/client/src/ui/modals.js b/client/src/ui/modals.js index 655571b1..e98e7564 100644 --- a/client/src/ui/modals.js +++ b/client/src/ui/modals.js @@ -12,8 +12,6 @@ import { Utils, FileUtils } from 'common'; import { Events, PluginManager, ThemeManager } from 'modules'; import BasicModal from './components/bd/modals/BasicModal.vue'; import ErrorModal from './components/bd/modals/ErrorModal.vue'; -import PluginSettingsModal from './components/bd/modals/PluginSettingsModal.vue'; -import ThemeSettingsModal from './components/bd/modals/ThemeSettingsModal.vue'; import SettingsModal from './components/bd/modals/SettingsModal.vue'; export default class { @@ -105,11 +103,13 @@ export default class { } static pluginSettings(plugin) { - return this.add({ plugin }, PluginSettingsModal); + // return this.add({ headertext: plugin.name + ' Settings', settings: plugin.config, saveSettings: plugin.saveSettings }, SettingsModal); + return this.settings(plugin.name + ' Settings', plugin.config, null, null, plugin.saveSettings.bind(plugin)); } static themeSettings(theme) { - return this.add({ theme }, ThemeSettingsModal); + // return this.add({ headertext: theme.name + ' Settings', settings: theme.config, saveSettings: theme.saveSettings }, SettingsModal); + return this.settings(theme.name + ' Settings', theme.config, null, null, theme.saveSettings.bind(theme)); } static get stack() { From 145df5e7cc51d8868e6f79dc58f515391516646d Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Wed, 14 Feb 2018 01:45:41 +0000 Subject: [PATCH 04/11] Add Plugin.config --- client/src/modules/plugin.js | 7 ++++--- client/src/ui/modals.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/client/src/modules/plugin.js b/client/src/modules/plugin.js index 1ebcffaa..cc731c0b 100644 --- a/client/src/modules/plugin.js +++ b/client/src/modules/plugin.js @@ -36,7 +36,8 @@ export default class Plugin { get pluginPath() { return this.paths.contentPath } get dirName() { return this.paths.dirName } get enabled() { return this.userConfig.enabled } - get pluginConfig() { return this.userConfig.config || [] } + get config() { return this.userConfig.config || [] } + get pluginConfig() { return this.config } get exports() { return this._exports ? this._exports : (this._exports = this.getExports()) } getSetting(setting_id, category_id) { @@ -57,7 +58,7 @@ export default class Plugin { const updatedSettings = []; for (let newCategory of newSettings) { - const category = this.pluginConfig.find(c => c.category === newCategory.category); + const category = this.config.find(c => c.category === newCategory.category); for (let newSetting of newCategory.settings) { const setting = category.settings.find(s => s.id === newSetting.id); if (Utils.compare(setting.value, newSetting.value)) continue; @@ -80,7 +81,7 @@ export default class Plugin { try { await FileUtils.writeFile(`${this.pluginPath}/user.config.json`, JSON.stringify({ enabled: this.enabled, - config: this.pluginConfig.map(category => { + config: this.config.map(category => { return { category: category.category, settings: category.settings.map(setting => { diff --git a/client/src/ui/modals.js b/client/src/ui/modals.js index e98e7564..33b2b918 100644 --- a/client/src/ui/modals.js +++ b/client/src/ui/modals.js @@ -109,7 +109,7 @@ export default class { static themeSettings(theme) { // return this.add({ headertext: theme.name + ' Settings', settings: theme.config, saveSettings: theme.saveSettings }, SettingsModal); - return this.settings(theme.name + ' Settings', theme.config, null, null, theme.saveSettings.bind(theme)); + return this.settings(theme.name + ' Settings', theme.themeConfig, null, null, theme.saveSettings.bind(theme)); } static get stack() { From 8e71ee5a5cb1a57d6bbc3a387996bc806e44282d Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Wed, 14 Feb 2018 01:48:21 +0000 Subject: [PATCH 05/11] Undo stuff from samuelthomas2774/add-setting-events --- client/src/modules/plugin.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/client/src/modules/plugin.js b/client/src/modules/plugin.js index cc731c0b..b104c921 100644 --- a/client/src/modules/plugin.js +++ b/client/src/modules/plugin.js @@ -55,18 +55,13 @@ export default class Plugin { } async saveSettings(newSettings) { - const updatedSettings = []; - - for (let newCategory of newSettings) { - const category = this.config.find(c => c.category === newCategory.category); - for (let newSetting of newCategory.settings) { - const setting = category.settings.find(s => s.id === newSetting.id); - if (Utils.compare(setting.value, newSetting.value)) continue; - - let old_value = setting.value; - setting.value = newSetting.value; - updatedSettings.push({ category_id: category.category, setting_id: setting.id, value: setting.value, old_value }); - this.settingUpdated(category.category, setting.id, setting.value, old_value); + for (let category of newSettings) { + const oldCategory = this.pluginConfig.find(c => c.category === category.category); + for (let setting of category.settings) { + const oldSetting = oldCategory.settings.find(s => s.id === setting.id); + if (Utils.compare(oldSetting.value, setting.value)) continue; + oldSetting.value = setting.value; + if (this.settingChanged) this.settingChanged(category.category, setting.id, setting.value); } } From cebaba2de35b33b8648cf1885197167c6a873efd Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Wed, 14 Feb 2018 01:52:45 +0000 Subject: [PATCH 06/11] Fix file setting --- client/src/ui/components/bd/setting/File.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/ui/components/bd/setting/File.vue b/client/src/ui/components/bd/setting/File.vue index 4154b244..f7f26e46 100644 --- a/client/src/ui/components/bd/setting/File.vue +++ b/client/src/ui/components/bd/setting/File.vue @@ -49,7 +49,7 @@ shell.openItem(file_path); }, removeItem(file_path) { - this.change(this.setting.id, this.setting.value.filter(f => f !== file_path)); + this.change(this.setting.value.filter(f => f !== file_path)); } } } From 1dd01e186b68fdd7f0bad49546cb9521ffcad23e Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Wed, 14 Feb 2018 15:45:10 +0000 Subject: [PATCH 07/11] Use Plugin/Theme.config --- client/src/modules/plugin.js | 10 +++++----- client/src/modules/theme.js | 12 ++++++------ client/src/ui/modals.js | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/client/src/modules/plugin.js b/client/src/modules/plugin.js index 68955d5e..b4fd7fec 100644 --- a/client/src/modules/plugin.js +++ b/client/src/modules/plugin.js @@ -38,7 +38,7 @@ export default class Plugin { constructor(pluginInternals) { this.__pluginInternals = pluginInternals; this.saveSettings = this.saveSettings.bind(this); - this.hasSettings = this.pluginConfig && this.pluginConfig.length > 0; + this.hasSettings = this.config && this.config.length > 0; this.start = this.start.bind(this); this.stop = this.stop.bind(this); } @@ -64,7 +64,7 @@ export default class Plugin { get events() { return this.EventEmitter ? this.EventEmitter : (this.EventEmitter = new PluginEvents(this)) } getSetting(setting_id, category_id) { - for (let category of this.pluginConfig) { + for (let category of this.config) { if (category_id && category.category !== category_id) return; for (let setting of category.settings) { if (setting.id !== setting_id) return; @@ -81,7 +81,7 @@ export default class Plugin { const updatedSettings = []; for (let newCategory of newSettings) { - const category = this.pluginConfig.find(c => c.category === newCategory.category); + const category = this.config.find(c => c.category === newCategory.category); for (let newSetting of newCategory.settings) { const setting = category.settings.find(s => s.id === newSetting.id); if (Utils.compare(setting.value, newSetting.value)) continue; @@ -109,9 +109,9 @@ export default class Plugin { } async saveConfiguration() { - window.testConfig = new ContentConfig(this.pluginConfig); + window.testConfig = new ContentConfig(this.config); try { - const config = new ContentConfig(this.pluginConfig).strip(); + const config = new ContentConfig(this.config).strip(); await FileUtils.writeFile(`${this.pluginPath}/user.config.json`, JSON.stringify({ enabled: this.enabled, config diff --git a/client/src/modules/theme.js b/client/src/modules/theme.js index 5cf124e9..75506d9e 100644 --- a/client/src/modules/theme.js +++ b/client/src/modules/theme.js @@ -12,7 +12,7 @@ import ThemeManager from './thememanager'; import { EventEmitter } from 'events'; import { SettingUpdatedEvent, SettingsUpdatedEvent } from 'structs'; import { DOM, Modals } from 'ui'; -import { FileUtils, ClientIPC } from 'common'; +import { Utils, FileUtils, ClientIPC } from 'common'; import ContentConfig from './contentconfig'; class ThemeEvents { @@ -38,7 +38,7 @@ export default class Theme { constructor(themeInternals) { this.__themeInternals = themeInternals; - this.hasSettings = this.themeConfig && this.themeConfig.length > 0; + this.hasSettings = this.config && this.config.length > 0; this.saveSettings = this.saveSettings.bind(this); this.enable = this.enable.bind(this); this.disable = this.disable.bind(this); @@ -71,10 +71,10 @@ export default class Theme { const updatedSettings = []; for (let newCategory of newSettings) { - const category = this.themeConfig.find(c => c.category === newCategory.category); + const category = this.config.find(c => c.category === newCategory.category); for (let newSetting of newCategory.settings) { const setting = category.settings.find(s => s.id === newSetting.id); - if (setting.value === newSetting.value) continue; + if (Utils.compare(setting.value, newSetting.value)) continue; const old_value = setting.value; setting.value = newSetting.value; @@ -103,7 +103,7 @@ export default class Theme { async saveConfiguration() { try { - const config = new ContentConfig(this.themeConfig).strip(); + const config = new ContentConfig(this.config).strip(); await FileUtils.writeFile(`${this.themePath}/user.config.json`, JSON.stringify({ enabled: this.enabled, config, @@ -134,7 +134,7 @@ export default class Theme { let css = ''; if (this.info.type === 'sass') { css = await ClientIPC.send('bd-compileSass', { - data: ThemeManager.getConfigAsSCSS(this.themeConfig), + data: ThemeManager.getConfigAsSCSS(this.config), path: this.paths.mainPath.replace(/\\/g, '/') }); console.log(css); diff --git a/client/src/ui/modals.js b/client/src/ui/modals.js index 33b2b918..e98e7564 100644 --- a/client/src/ui/modals.js +++ b/client/src/ui/modals.js @@ -109,7 +109,7 @@ export default class { static themeSettings(theme) { // return this.add({ headertext: theme.name + ' Settings', settings: theme.config, saveSettings: theme.saveSettings }, SettingsModal); - return this.settings(theme.name + ' Settings', theme.themeConfig, null, null, theme.saveSettings.bind(theme)); + return this.settings(theme.name + ' Settings', theme.config, null, null, theme.saveSettings.bind(theme)); } static get stack() { From 41b790661249eae41e8bfaf8ac0d2e93473ca7bc Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Wed, 14 Feb 2018 16:11:26 +0000 Subject: [PATCH 08/11] Use Utils.compare for internal settings --- client/src/modules/settings.js | 26 ++++++++++++++++++++++++-- client/src/ui/modals.js | 8 +++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/client/src/modules/settings.js b/client/src/modules/settings.js index 16c6e64e..12d84adc 100644 --- a/client/src/modules/settings.js +++ b/client/src/modules/settings.js @@ -12,7 +12,7 @@ import defaultSettings from '../data/user.settings.default'; import Globals from './globals'; import CssEditor from './csseditor'; import Events from './events'; -import { FileUtils, ClientLogger as Logger } from 'common'; +import { Utils, FileUtils, ClientLogger as Logger } from 'common'; import { SettingUpdatedEvent } from 'structs'; import path from 'path'; @@ -113,6 +113,28 @@ export default class { return setting ? setting.value : undefined; } + static saveSettings(set_id, newSettings, settingsUpdated) { + const set = this.getSet(set_id); + if (!set) return; + const updatedSettings = []; + + for (let newCategory of newSettings) { + let category = set.settings.find(c => c.category === newCategory.category); + + for (let newSetting of newCategory.settings) { + let setting = category.settings.find(s => s.id === newSetting.id); + if (Utils.compare(setting.value, newSetting.value)) continue; + + let old_value = setting.value; + setting.value = newSetting.value; + updatedSettings.push({ set_id: set.id, category_id: category.category, setting_id: setting.id, value: setting.value, old_value }); + this.settingUpdated(set.id, category.category, setting.id, setting.value, old_value); + } + } + + return settingsUpdated ? settingsUpdated(updatedSettings) : updatedSettings; + } + static setSetting(set_id, category_id, setting_id, value) { for (let set of this.getSettings) { if (set.id !== set_id) continue; @@ -122,7 +144,7 @@ export default class { for (let setting of category.settings) { if (setting.id !== setting_id) continue; - if (setting.value === value) return true; + if (Utils.compare(setting.value, value)) return true; let old_value = setting.value; setting.value = value; diff --git a/client/src/ui/modals.js b/client/src/ui/modals.js index e98e7564..001ffa6c 100644 --- a/client/src/ui/modals.js +++ b/client/src/ui/modals.js @@ -9,7 +9,7 @@ */ import { Utils, FileUtils } from 'common'; -import { Events, PluginManager, ThemeManager } from 'modules'; +import { Settings, Events, PluginManager, ThemeManager } from 'modules'; import BasicModal from './components/bd/modals/BasicModal.vue'; import ErrorModal from './components/bd/modals/ErrorModal.vue'; import SettingsModal from './components/bd/modals/SettingsModal.vue'; @@ -102,6 +102,12 @@ export default class { }, SettingsModal); } + static internalSettings(set_id) { + const set = Settings.getSet(set_id); + if (!set) return; + return this.settings(set.headertext, set.settings, null, null, newSettings => Settings.saveSettings(set.id, newSettings)); + } + static pluginSettings(plugin) { // return this.add({ headertext: plugin.name + ' Settings', settings: plugin.config, saveSettings: plugin.saveSettings }, SettingsModal); return this.settings(plugin.name + ' Settings', plugin.config, null, null, plugin.saveSettings.bind(plugin)); From 8c5796e4f6de5ad89bca62add1473b34c1cfd5c7 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Wed, 14 Feb 2018 16:14:59 +0000 Subject: [PATCH 09/11] Remove old code --- client/src/ui/modals.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/src/ui/modals.js b/client/src/ui/modals.js index 001ffa6c..4cecb25f 100644 --- a/client/src/ui/modals.js +++ b/client/src/ui/modals.js @@ -109,12 +109,10 @@ export default class { } static pluginSettings(plugin) { - // return this.add({ headertext: plugin.name + ' Settings', settings: plugin.config, saveSettings: plugin.saveSettings }, SettingsModal); return this.settings(plugin.name + ' Settings', plugin.config, null, null, plugin.saveSettings.bind(plugin)); } static themeSettings(theme) { - // return this.add({ headertext: theme.name + ' Settings', settings: theme.config, saveSettings: theme.saveSettings }, SettingsModal); return this.settings(theme.name + ' Settings', theme.config, null, null, theme.saveSettings.bind(theme)); } From dcb2704a283159eebd0d1d22c098fe9cf0578d0a Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Wed, 14 Feb 2018 16:22:48 +0000 Subject: [PATCH 10/11] Merge Modals.pluginSettings and Modals.themeSettings to a single function for both --- client/src/modules/plugin.js | 2 +- client/src/modules/theme.js | 2 +- client/src/ui/components/bd/PluginsView.vue | 2 +- client/src/ui/components/bd/ThemesView.vue | 2 +- client/src/ui/modals.js | 8 ++------ 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/client/src/modules/plugin.js b/client/src/modules/plugin.js index b4fd7fec..3c944897 100644 --- a/client/src/modules/plugin.js +++ b/client/src/modules/plugin.js @@ -74,7 +74,7 @@ export default class Plugin { } showSettingsModal() { - return Modals.pluginSettings(this); + return Modals.contentSettings(this); } async saveSettings(newSettings) { diff --git a/client/src/modules/theme.js b/client/src/modules/theme.js index 75506d9e..34081010 100644 --- a/client/src/modules/theme.js +++ b/client/src/modules/theme.js @@ -64,7 +64,7 @@ export default class Theme { get events() { return this.EventEmitter ? this.EventEmitter : (this.EventEmitter = new ThemeEvents(this)) } showSettingsModal() { - return Modals.themeSettings(this); + return Modals.contentSettings(this); } async saveSettings(newSettings) { diff --git a/client/src/ui/components/bd/PluginsView.vue b/client/src/ui/components/bd/PluginsView.vue index 306bd84b..d7a664ed 100644 --- a/client/src/ui/components/bd/PluginsView.vue +++ b/client/src/ui/components/bd/PluginsView.vue @@ -89,7 +89,7 @@ })(); }, showSettings(plugin) { - return Modals.pluginSettings(plugin); + return Modals.contentSettings(plugin); } } } diff --git a/client/src/ui/components/bd/ThemesView.vue b/client/src/ui/components/bd/ThemesView.vue index c98f389b..101a06e7 100644 --- a/client/src/ui/components/bd/ThemesView.vue +++ b/client/src/ui/components/bd/ThemesView.vue @@ -89,7 +89,7 @@ })(); }, showSettings(theme) { - return Modals.themeSettings(theme); + return Modals.contentSettings(theme); } } } diff --git a/client/src/ui/modals.js b/client/src/ui/modals.js index 4cecb25f..e4e869c1 100644 --- a/client/src/ui/modals.js +++ b/client/src/ui/modals.js @@ -108,12 +108,8 @@ export default class { return this.settings(set.headertext, set.settings, null, null, newSettings => Settings.saveSettings(set.id, newSettings)); } - static pluginSettings(plugin) { - return this.settings(plugin.name + ' Settings', plugin.config, null, null, plugin.saveSettings.bind(plugin)); - } - - static themeSettings(theme) { - return this.settings(theme.name + ' Settings', theme.config, null, null, theme.saveSettings.bind(theme)); + static contentSettings(content) { + return this.settings(content.name + ' Settings', content.config, null, null, content.saveSettings.bind(content)); } static get stack() { From 0cfb6d36ca040442b4a8f4d42189d848e46a5a3e Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Wed, 14 Feb 2018 16:32:12 +0000 Subject: [PATCH 11/11] Rename new Settings.saveSettings to Settings.mergeSettings --- client/src/modules/csseditor.js | 8 ++++---- client/src/modules/settings.js | 3 ++- client/src/ui/modals.js | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/client/src/modules/csseditor.js b/client/src/modules/csseditor.js index 9f686ded..75144ca6 100644 --- a/client/src/modules/csseditor.js +++ b/client/src/modules/csseditor.js @@ -41,7 +41,7 @@ export default class { /** * Update css in client * @param {String} scss scss to compile - * @param {bool} sendSource send to css editor instance + * @param {bool} sendSource send to css editor instance */ static updateScss(scss, sendSource) { if (sendSource) @@ -86,7 +86,7 @@ export default class { /** * Send css to open editor - * @param {any} channel + * @param {any} channel * @param {any} data */ static async sendToEditor(channel, data) { @@ -94,14 +94,14 @@ export default class { } /** - * Current uncompiled scss + * Current uncompiled scss */ static get scss() { return this._scss || ''; } /** - * Set current scss + * Set current scss */ static set scss(scss) { this.updateScss(scss, true); diff --git a/client/src/modules/settings.js b/client/src/modules/settings.js index 12d84adc..ff07f7ac 100644 --- a/client/src/modules/settings.js +++ b/client/src/modules/settings.js @@ -113,7 +113,7 @@ export default class { return setting ? setting.value : undefined; } - static saveSettings(set_id, newSettings, settingsUpdated) { + static mergeSettings(set_id, newSettings, settingsUpdated) { const set = this.getSet(set_id); if (!set) return; const updatedSettings = []; @@ -132,6 +132,7 @@ export default class { } } + this.saveSettings(); return settingsUpdated ? settingsUpdated(updatedSettings) : updatedSettings; } diff --git a/client/src/ui/modals.js b/client/src/ui/modals.js index e4e869c1..4cd0e467 100644 --- a/client/src/ui/modals.js +++ b/client/src/ui/modals.js @@ -105,7 +105,7 @@ export default class { static internalSettings(set_id) { const set = Settings.getSet(set_id); if (!set) return; - return this.settings(set.headertext, set.settings, null, null, newSettings => Settings.saveSettings(set.id, newSettings)); + return this.settings(set.headertext, set.settings, null, null, newSettings => Settings.mergeSettings(set.id, newSettings)); } static contentSettings(content) {