Merge pull request #115 from samuelthomas2774/plugin-theme-configuration
Remove unnecessary information when saving plugin/theme configuration
This commit is contained in:
commit
35338dd104
|
@ -39,42 +39,56 @@ export default class {
|
||||||
return this.userConfig.config.find(setting => setting.id === settingId);
|
return this.userConfig.config.find(setting => setting.id === settingId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async sleep(ms) {
|
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
|
||||||
}
|
|
||||||
|
|
||||||
async saveSettings(newSettings) {
|
async saveSettings(newSettings) {
|
||||||
if (newSettings) {
|
for (let category of newSettings) {
|
||||||
for (let category of newSettings) {
|
const oldCategory = this.pluginConfig.find(c => c.category === category.category);
|
||||||
const oldCategory = this.pluginConfig.find(c => c.category === category.category);
|
for (let setting of category.settings) {
|
||||||
for (let setting of category.settings) {
|
const oldSetting = oldCategory.settings.find(s => s.id === setting.id);
|
||||||
const oldSetting = oldCategory.settings.find(s => s.id === setting.id);
|
if (oldSetting.value === setting.value) continue;
|
||||||
if (oldSetting.value === setting.value) continue;
|
oldSetting.value = setting.value;
|
||||||
oldSetting.value = setting.value;
|
if (this.settingChanged) this.settingChanged(category.category, setting.id, setting.value);
|
||||||
if (this.settingChanged) this.settingChanged(category.category, setting.id, setting.value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
this.saveConfiguration();
|
||||||
await FileUtils.writeFile(`${this.pluginPath}/user.config.json`, JSON.stringify({ enabled: this.enabled, config: this.pluginConfig }));
|
|
||||||
} catch (err) {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.settingsChanged) this.settingsChanged(this.pluginConfig);
|
if (this.settingsChanged) this.settingsChanged(this.pluginConfig);
|
||||||
|
|
||||||
return 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() {
|
start() {
|
||||||
if (this.onStart) {
|
if (this.onStart) {
|
||||||
const started = this.onStart();
|
const started = this.onStart();
|
||||||
if (!started) return false;
|
if (!started) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.userConfig.enabled = true;
|
if (!this.enabled) {
|
||||||
this.saveSettings();
|
this.userConfig.enabled = true;
|
||||||
|
this.saveConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +99,7 @@ export default class {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.userConfig.enabled = false;
|
this.userConfig.enabled = false;
|
||||||
this.saveSettings();
|
this.saveConfiguration();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,17 @@ class Theme {
|
||||||
try {
|
try {
|
||||||
await FileUtils.writeFile(`${this.themePath}/user.config.json`, JSON.stringify({
|
await FileUtils.writeFile(`${this.themePath}/user.config.json`, JSON.stringify({
|
||||||
enabled: this.enabled,
|
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
|
css: this.css
|
||||||
}));
|
}));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
Loading…
Reference in New Issue