From 69fc8422d1dfcafed7a890accda207031cf4cd30 Mon Sep 17 00:00:00 2001 From: lloyd <353627866@qq.com> Date: Thu, 11 Sep 2025 16:24:29 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E3=80=90=E5=AE=9E=E7=8E=B0=E9=94=AE?= =?UTF-8?q?=E5=80=BC=E5=9E=8B=E6=95=B0=E6=8D=AE=E5=BA=93=E8=AF=BB=E5=86=99?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E3=80=91=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/common/utils/KVStore.ets | 7 ++++--- entry/src/main/ets/pages/ReadWritePage.ets | 13 ++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/entry/src/main/ets/common/utils/KVStore.ets b/entry/src/main/ets/common/utils/KVStore.ets index 320f003..b7f66d9 100644 --- a/entry/src/main/ets/common/utils/KVStore.ets +++ b/entry/src/main/ets/common/utils/KVStore.ets @@ -18,8 +18,7 @@ import { distributedKVStore } from '@kit.ArkData'; import { bundleManager } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { KVStoreType } from '../../viewmodel/KVStoreType'; - -let UIContext: UIContext +import { BusinessError } from '@kit.BasicServicesKit'; export default class KVStore { private kvManager: distributedKVStore.KVManager | undefined = undefined; @@ -90,7 +89,9 @@ export default class KVStore { let kvStoreType = new KVStoreType(entries[i].key, entries[i].value.value, type); allKVStore.push(kvStoreType); } - }); + }).catch((error: BusinessError) =>{ + hilog.error(0x0000, 'KVStore', `Failed to getEntries. Code:${error.code},message:${error.message}`); + }) hilog.info(0x0000, 'KVStore', `kvStoreType: ${JSON.stringify(allKVStore)}`); return allKVStore; } diff --git a/entry/src/main/ets/pages/ReadWritePage.ets b/entry/src/main/ets/pages/ReadWritePage.ets index 2230032..23fb8d2 100644 --- a/entry/src/main/ets/pages/ReadWritePage.ets +++ b/entry/src/main/ets/pages/ReadWritePage.ets @@ -16,6 +16,8 @@ import { buffer, util } from '@kit.ArkTS'; import KVStore from '../common/utils/KVStore'; import { KVStoreType } from '../viewmodel/KVStoreType'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; @Extend(Text) function tableStyle() { @@ -48,7 +50,6 @@ export struct ReadWrite { @State index: number = 0; private inputKey: string = ''; private inputValue: Uint8Array | string | number | boolean = ''; - UIContext = this.getUIContext(); @Builder @@ -422,4 +423,14 @@ export struct ReadWrite { .title(this.UIContext.getHostContext()?.resourceManager.getStringSync($r('app.string.destination_title').id)) .backgroundColor('#F1F3F5') } + + getString(id: number): string { + try { + return this.UIContext.getHostContext()?.resourceManager.getStringSync(id) ?? ''; + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'ReadWrite', `getStringSync failed, error code=${err.code}, message=${err.code}`); + return ''; + } + } } \ No newline at end of file -- Gitee From e0ac7d90d6c37558f4ab007e6f4ac34a394a2500 Mon Sep 17 00:00:00 2001 From: lloyd <353627866@qq.com> Date: Thu, 11 Sep 2025 16:25:57 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E3=80=90=E5=AE=9E=E7=8E=B0=E9=94=AE?= =?UTF-8?q?=E5=80=BC=E5=9E=8B=E6=95=B0=E6=8D=AE=E5=BA=93=E8=AF=BB=E5=86=99?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E3=80=91=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/ReadWritePage.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entry/src/main/ets/pages/ReadWritePage.ets b/entry/src/main/ets/pages/ReadWritePage.ets index 23fb8d2..3ff0a04 100644 --- a/entry/src/main/ets/pages/ReadWritePage.ets +++ b/entry/src/main/ets/pages/ReadWritePage.ets @@ -420,7 +420,7 @@ export struct ReadWrite { } .width('100%') .height('100%') - .title(this.UIContext.getHostContext()?.resourceManager.getStringSync($r('app.string.destination_title').id)) + .title(this.getString($r('app.string.destination_title').id)) .backgroundColor('#F1F3F5') } -- Gitee From a097beb8674e173c37722207cccd8eafc7f9d5fc Mon Sep 17 00:00:00 2001 From: lloyd <353627866@qq.com> Date: Thu, 11 Sep 2025 16:29:51 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E3=80=90=E5=AE=9E=E7=8E=B0=E9=94=AE?= =?UTF-8?q?=E5=80=BC=E5=9E=8B=E6=95=B0=E6=8D=AE=E5=BA=93=E8=AF=BB=E5=86=99?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E3=80=91=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hvigor/hvigor-config.json5 | 2 +- oh-package.json5 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hvigor/hvigor-config.json5 b/hvigor/hvigor-config.json5 index 06b2783..5bebc97 100644 --- a/hvigor/hvigor-config.json5 +++ b/hvigor/hvigor-config.json5 @@ -1,5 +1,5 @@ { - "modelVersion": "5.0.0", + "modelVersion": "5.0.5", "dependencies": { }, "execution": { diff --git a/oh-package.json5 b/oh-package.json5 index 8bf916d..2d9c74f 100644 --- a/oh-package.json5 +++ b/oh-package.json5 @@ -1,5 +1,5 @@ { - "modelVersion": "5.0.0", + "modelVersion": "5.0.5", "description": "Please describe the basic information.", "dependencies": { }, -- Gitee