* * @param {Object} [settings] - if provided, the settings will be updated * @param {Boolean} [showToast] - if false, the toast will not be shown * default is true * @param {Boolean} [saveFile] - if false, the settings will not be saved to the file, * default is true
(settings, showToast = true, saveFile = true)
| 299 | * default is true |
| 300 | */ |
| 301 | async update(settings, showToast = true, saveFile = true) { |
| 302 | if (typeof settings === "boolean") { |
| 303 | showToast = settings; |
| 304 | settings = undefined; |
| 305 | } |
| 306 | |
| 307 | const onupdate = [...this.#on.update]; |
| 308 | const onupdateAfter = [...this.#on["update:after"]]; |
| 309 | |
| 310 | if (settings) { |
| 311 | Object.keys(settings).forEach((key) => { |
| 312 | if (key in this.value) this.value[key] = settings[key]; |
| 313 | }); |
| 314 | } |
| 315 | |
| 316 | const changedSettings = this.#getChangedKeys(); |
| 317 | changedSettings.forEach((setting) => { |
| 318 | this.#applySettings(setting); |
| 319 | const listeners = this.#on[`update:${setting}`]; |
| 320 | if (Array.isArray(listeners)) { |
| 321 | onupdate.push(...listeners); |
| 322 | } |
| 323 | onupdate.forEach((listener) => listener(this.value[setting])); |
| 324 | }); |
| 325 | |
| 326 | if (saveFile) await this.#save(); |
| 327 | |
| 328 | changedSettings.forEach((setting) => { |
| 329 | const listeners = this.#on[`update:${setting}:after`]; |
| 330 | if (Array.isArray(listeners)) { |
| 331 | onupdateAfter.push(...listeners); |
| 332 | } |
| 333 | onupdateAfter.forEach((listener) => listener(this.value[setting])); |
| 334 | }); |
| 335 | } |
| 336 | |
| 337 | async reset(setting) { |
| 338 | if (setting) { |
no test coverage detected