commit
a0fb11d591
|
@ -38,18 +38,31 @@ export default class {
|
||||||
return this.userConfig.config.find(setting => setting.id === settingId);
|
return this.userConfig.config.find(setting => setting.id === settingId);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveSettings(newSettings) {
|
async sleep(ms) {
|
||||||
console.log(this);
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
let changed = false;
|
}
|
||||||
for (let newSetting of newSettings) {
|
|
||||||
const setting = this.pluginConfig.find(s => s.id === newSetting.id && s.value !== newSetting.value);
|
async saveSettings(newSettings) {
|
||||||
if (!setting) continue;
|
await this.sleep(2000); // Fake sleep to test loading
|
||||||
setting.value = newSetting.value;
|
for (let category of newSettings) {
|
||||||
if (this.settingSaved) this.settingSaved(setting);
|
const oldCategory = this.pluginConfig.find(c => c.category === category.category);
|
||||||
changed = true;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (changed && this.settingsSaved) this.settingsSaved(this.pluginConfig);
|
|
||||||
FileUtils.writeFile(`${this.pluginPath}/user.config.json`, JSON.stringify({enabled: this.enabled, config: this.pluginConfig}));
|
try {
|
||||||
|
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);
|
||||||
|
|
||||||
|
return this.pluginConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
|
|
|
@ -3,6 +3,12 @@
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bd-modal .bd-modal-footer {
|
||||||
|
.bd-ok {
|
||||||
|
width: 100px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.bd-plugin-settings-body {
|
.bd-plugin-settings-body {
|
||||||
padding: 0 15px;
|
padding: 0 15px;
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,13 @@
|
||||||
</div>
|
</div>
|
||||||
<div slot="footer" class="bd-footer-alert" :class ="{'bd-active': changed, 'bd-warn': warnclose}">
|
<div slot="footer" class="bd-footer-alert" :class ="{'bd-active': changed, 'bd-warn': warnclose}">
|
||||||
<div class="bd-footer-alert-text">Unsaved changes</div>
|
<div class="bd-footer-alert-text">Unsaved changes</div>
|
||||||
<div class="bd-button bd-reset-button bd-tp" @click="resetSettings">Reset</div>
|
<div class="bd-button bd-reset-button bd-tp" :class="{'bd-disabled': saving}" @click="resetSettings">Reset</div>
|
||||||
<div class="bd-button bd-ok" @click="saveSettings">Save Changes</div>
|
<div class="bd-button bd-ok" :class="{'bd-disabled': saving}" @click="saveSettings">
|
||||||
|
<div v-if="saving" class="bd-spinner-7"></div>
|
||||||
|
<template v-else>
|
||||||
|
Save Changes
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
|
@ -53,7 +58,8 @@
|
||||||
changed: false,
|
changed: false,
|
||||||
warnclose: false,
|
warnclose: false,
|
||||||
configCache: [],
|
configCache: [],
|
||||||
closing: false
|
closing: false,
|
||||||
|
saving: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
@ -81,13 +87,21 @@
|
||||||
}
|
}
|
||||||
this.changed = this.checkForChanges();
|
this.changed = this.checkForChanges();
|
||||||
},
|
},
|
||||||
saveSettings() {
|
async saveSettings() {
|
||||||
//this.plugin.saveSettings(this.configCache);
|
if (this.saving) return;
|
||||||
//this.configCache = JSON.parse(JSON.stringify(this.plugin.pluginConfig));
|
this.saving = true;
|
||||||
// TODO later
|
try {
|
||||||
this.changed = false;
|
await this.plugin.saveSettings(this.configCache);
|
||||||
|
this.configCache = JSON.parse(JSON.stringify(this.plugin.pluginConfig));
|
||||||
|
this.changed = false;
|
||||||
|
} catch (err) {
|
||||||
|
// TODO Display error that settings failed to save
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
this.saving = false;
|
||||||
},
|
},
|
||||||
resetSettings() {
|
resetSettings() {
|
||||||
|
if (this.saving) return;
|
||||||
this.configCache = JSON.parse(JSON.stringify(this.plugin.pluginConfig));
|
this.configCache = JSON.parse(JSON.stringify(this.plugin.pluginConfig));
|
||||||
this.changed = false;
|
this.changed = false;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue