Merge pull request #115 from samuelthomas2774/plugin-theme-configuration

Remove unnecessary information when saving plugin/theme configuration
This commit is contained in:
Alexei Stukov 2018-02-11 23:45:52 +02:00 committed by GitHub
commit 35338dd104
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 22 deletions

View File

@ -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;
}

View File

@ -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) {