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/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/plugin.js b/client/src/modules/plugin.js index 25cca7a7..3c944897 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'; import { EventEmitter } from 'events'; import ContentConfig from './contentconfig'; @@ -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; @@ -74,17 +74,17 @@ export default class Plugin { } showSettingsModal() { - return Modals.pluginSettings(this); + return Modals.contentSettings(this); } async saveSettings(newSettings) { 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 (setting.value === newSetting.value) continue; + if (Utils.compare(setting.value, newSetting.value)) continue; const old_value = setting.value; setting.value = newSetting.value; @@ -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/settings.js b/client/src/modules/settings.js index 16c6e64e..ff07f7ac 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,29 @@ export default class { return setting ? setting.value : undefined; } + static mergeSettings(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); + } + } + + this.saveSettings(); + 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 +145,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/modules/theme.js b/client/src/modules/theme.js index 5cf124e9..34081010 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); @@ -64,17 +64,17 @@ 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) { 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/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/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/bdsettings/plugin-settings-modal.scss b/client/src/styles/partials/modals/settings-modal.scss similarity index 89% rename from client/src/styles/partials/bdsettings/plugin-settings-modal.scss rename to client/src/styles/partials/modals/settings-modal.scss index fd423cb0..fd3513a8 100644 --- a/client/src/styles/partials/bdsettings/plugin-settings-modal.scss +++ b/client/src/styles/partials/modals/settings-modal.scss @@ -1,4 +1,4 @@ -.bd-plugin-settings-modal { +.bd-settings-modal { .bd-modal .bd-modal-body { padding: 0; } @@ -9,7 +9,7 @@ } } - .bd-plugin-settings-body { + .bd-settings-modal-body { padding: 0 15px; margin: 0 0 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/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/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 @@