diff --git a/client/src/modules/plugin.js b/client/src/modules/plugin.js index 4a6aaa48..b78cb5fb 100644 --- a/client/src/modules/plugin.js +++ b/client/src/modules/plugin.js @@ -39,42 +39,56 @@ export default class { return this.userConfig.config.find(setting => setting.id === settingId); } - async sleep(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); - } - async saveSettings(newSettings) { - if (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); - } + 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); } } - try { - await FileUtils.writeFile(`${this.pluginPath}/user.config.json`, JSON.stringify({ enabled: this.enabled, config: this.pluginConfig })); - } catch (err) { - throw err; - } + this.saveConfiguration(); if (this.settingsChanged) this.settingsChanged(this.pluginConfig); return this.pluginConfig; } + async saveConfiguration() { + try { + await FileUtils.writeFile(`${this.pluginPath}/user.config.json`, JSON.stringify({ + enabled: this.enabled, + config: this.pluginConfig.map(category => { + return { + category: category.category, + settings: category.settings.map(setting => { + return { + id: setting.id, + value: setting.value + }; + }) + }; + }) + })); + } catch (err) { + throw err; + } + } + start() { if (this.onStart) { const started = this.onStart(); if (!started) return false; } - this.userConfig.enabled = true; - this.saveSettings(); + if (!this.enabled) { + this.userConfig.enabled = true; + this.saveConfiguration(); + } + return true; } @@ -85,7 +99,7 @@ export default class { } this.userConfig.enabled = false; - this.saveSettings(); + this.saveConfiguration(); return true; } diff --git a/client/src/modules/thememanager.js b/client/src/modules/thememanager.js index cc032e7c..fd828adf 100644 --- a/client/src/modules/thememanager.js +++ b/client/src/modules/thememanager.js @@ -63,7 +63,17 @@ class Theme { try { await FileUtils.writeFile(`${this.themePath}/user.config.json`, JSON.stringify({ enabled: this.enabled, - config: this.themeConfig, + config: this.themeConfig.map(category => { + return { + category: category.category, + settings: category.settings.map(setting => { + return { + id: setting.id, + value: setting.value + }; + }) + }; + }), css: this.css })); } catch (err) {