update setting utils

This commit is contained in:
frostime 2023-10-27 22:11:43 +08:00
parent e2ed03218d
commit c580fb7a00

View file

@ -17,7 +17,7 @@ export class SettingUtils {
settings: Map<string, ISettingItem> = new Map(); settings: Map<string, ISettingItem> = new Map();
elements: Map<string, HTMLElement> = new Map(); elements: Map<string, HTMLElement> = new Map();
constructor(plugin: Plugin, name?: string, width?: string, height?: string) { constructor(plugin: Plugin, name?: string, width?: string, height?: string, callback?: (data: any) => void) {
this.name = name ?? 'settings'; this.name = name ?? 'settings';
this.plugin = plugin; this.plugin = plugin;
this.file = this.name.endsWith('.json') ? this.name : `${this.name}.json`; this.file = this.name.endsWith('.json') ? this.name : `${this.name}.json`;
@ -29,8 +29,12 @@ export class SettingUtils {
this.updateValue(key); this.updateValue(key);
} }
let data = this.dump(); let data = this.dump();
this.plugin.data[this.name] = data; if (callback !== undefined) {
this.save(); callback(data);
} else {
this.plugin.data[this.name] = data;
this.save();
}
} }
}); });
} }