diff --git a/client/src/modules/thememanager.js b/client/src/modules/thememanager.js
index 215846cc..32946afb 100644
--- a/client/src/modules/thememanager.js
+++ b/client/src/modules/thememanager.js
@@ -16,6 +16,8 @@ class Theme {
constructor(themeInternals) {
this.__themeInternals = themeInternals;
+ this.hasSettings = this.themeConfig && this.themeConfig.length > 0;
+ this.saveSettings = this.saveSettings.bind(this);
this.enable = this.enable.bind(this);
this.disable = this.disable.bind(this);
}
@@ -37,13 +39,39 @@ class Theme {
get css() { return this.__themeInternals.css }
get id() { return this.name.toLowerCase().replace(/\s+/g, '-') }
+ async saveSettings(newSettings) {
+ if (newSettings) {
+ for (let category of newSettings) {
+ const oldCategory = this.themeConfig.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.themePath}/user.config.json`, JSON.stringify({ enabled: this.enabled, config: this.themeConfig }));
+ } catch (err) {
+ throw err;
+ }
+
+ if (this.settingsChanged) this.settingsChanged(this.themeConfig);
+
+ return this.pluginConfig;
+ }
+
enable() {
this.userConfig.enabled = true;
+ this.saveSettings();
DOM.injectTheme(this.css, this.id);
}
disable() {
this.userConfig.enabled = false;
+ this.saveSettings();
DOM.deleteTheme(this.id);
}
@@ -68,21 +96,13 @@ export default class extends ContentManager {
try {
const css = await FileUtils.readFile(paths.mainPath);
const instance = new Theme({ configs, info, main, paths: { contentPath: paths.contentPath, dirName: paths.dirName }, css });
+ if (instance.enabled) instance.enable();
return instance;
} catch (err) {
throw err;
}
}
-
- static async loadPlugin(paths, configs, info, main) {
- const plugin = window.require(paths.mainPath)(Plugin, {}, {});
- const instance = new plugin({ configs, info, main, paths: { contentPath: paths.contentPath, dirName: paths.dirName } });
-
- if (instance.enabled) instance.start();
- return instance;
- }
-
static enableTheme(theme) {
theme.enable();
}
diff --git a/client/src/ui/components/bd/ThemeSettingsModal.vue b/client/src/ui/components/bd/ThemeSettingsModal.vue
new file mode 100644
index 00000000..31470091
--- /dev/null
+++ b/client/src/ui/components/bd/ThemeSettingsModal.vue
@@ -0,0 +1,134 @@
+/**
+ * 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.
+*/
+
+
+