Don't save unnecessary information with plugin/theme configuration

This commit is contained in:
Samuel Elliott 2018-02-11 21:30:35 +00:00
parent 0043292b25
commit 14822ab51a
2 changed files with 46 additions and 22 deletions

View File

@ -39,12 +39,7 @@ 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) {
@ -54,27 +49,46 @@ export default class {
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;
} }
if (!this.enabled) {
this.userConfig.enabled = true; this.userConfig.enabled = true;
this.saveSettings(); 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;
} }

View File

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