From 44d61785cf8dc9b8d42af3aa698ce7751b131965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=94=E9=98=B3=E9=99=8C=E5=AE=A2?= Date: Sat, 6 Apr 2024 01:44:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0setAndSave=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=BD=9C=E4=B8=BA=E8=AE=BE=E7=BD=AE=E5=8F=82=E6=95=B0=E5=B9=B6?= =?UTF-8?q?=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libs/setting-utils.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/libs/setting-utils.ts b/src/libs/setting-utils.ts index 17a850b..02053a2 100644 --- a/src/libs/setting-utils.ts +++ b/src/libs/setting-utils.ts @@ -80,6 +80,20 @@ export class SettingUtils { this.updateElementFromValue(key); } } + /** + * Set and save setting item value + * If you want to set and save immediately you can use this method + * @param key key name + * @param value value + */ + async setAndSave(key: string, value: any) { + let item = this.settings.get(key); + if (item) { + item.value = value; + this.updateElementFromValue(key); + await this.save() + } + } /** * Disable setting item