Merge pull request #99 from samuelthomas2774/save-plugin-enabled
Save plugin config when enabled/disabled
This commit is contained in:
commit
63b1e9d1e6
|
@ -44,6 +44,7 @@ export default class {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
@ -53,6 +54,7 @@ export default class {
|
|||
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 }));
|
||||
|
@ -68,25 +70,23 @@ export default class {
|
|||
start() {
|
||||
if (this.onStart) {
|
||||
const started = this.onStart();
|
||||
if (started) {
|
||||
return this.userConfig.enabled = true;
|
||||
if (!started) return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return this.userConfig.enabled = true; //Assume plugin started since it doesn't have onStart
|
||||
|
||||
this.userConfig.enabled = true;
|
||||
this.saveSettings();
|
||||
return true;
|
||||
}
|
||||
|
||||
stop() {
|
||||
if (this.onStop) {
|
||||
const stopped = this.onStop();
|
||||
if (stopped) {
|
||||
if (!stopped) return false;
|
||||
}
|
||||
|
||||
this.userConfig.enabled = false;
|
||||
this.saveSettings();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
this.userConfig.enabled = false;
|
||||
return true; //Assume plugin stopped since it doesn't have onStop
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue