Fix settings being partially saved while loading

This commit is contained in:
Samuel Elliott 2018-04-04 21:39:55 +01:00
parent cf319a2604
commit d4962bb2ab
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
3 changed files with 16 additions and 4 deletions

View File

@ -30,8 +30,8 @@ export default new class Settings {
Events.emit(`setting-updated-${set.id}_${category.id}_${setting.id}`, event);
});
set.on('settings-updated', async (event) => {
await this.saveSettings();
set.on('settings-updated', async event => {
if (!event.data || !event.data.dont_save) await this.saveSettings();
Events.emit('settings-updated', event);
});
@ -43,6 +43,8 @@ export default new class Settings {
* Loads BetterDiscord's settings.
*/
async loadSettings() {
Logger.log('Settings', ['Loading settings']);
try {
await FileUtils.ensureDirectory(this.dataPath);
@ -53,7 +55,7 @@ export default new class Settings {
for (let set of this.settings) {
const newSet = settings.find(s => s.id === set.id);
if (!newSet) continue;
await set.merge(newSet);
await set.merge(newSet, {dont_save: true});
set.setSaved();
}
@ -71,6 +73,8 @@ export default new class Settings {
* Saves BetterDiscord's settings including CSS editor data.
*/
async saveSettings() {
Logger.log('Settings', ['Saving settings']);
try {
await FileUtils.ensureDirectory(this.dataPath);

View File

@ -24,6 +24,13 @@ export default class Event {
return this.__eventInfo;
}
/**
* Extra data associated with this event.
*/
get data() {
return this.args.data;
}
/**
* The first argument that was passed to the constructor, which contains information about the event.
*/

View File

@ -412,7 +412,8 @@ export default class SettingsSet extends AsyncEventEmitter {
if (emit_multi)
await this.emit('settings-updated', new SettingsUpdatedEvent({
updatedSettings
updatedSettings,
data: typeof emit_multi !== 'boolean' ? emit_multi : undefined
}));
return updatedSettings;