From 829cf6adafa33b4e3d4408b64ff71adfd187f987 Mon Sep 17 00:00:00 2001 From: EasyGuohf <163991322+EasyGuohf@users.noreply.github.com> Date: Tue, 12 Aug 2025 16:56:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A7=84=E8=8C=83=E6=95=B4=E6=94=B9?= =?UTF-8?q?=EF=BC=9Atyr-catch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/common/utils/WindowUtil.ets | 6 ++-- webprerendersample/oh-package.json5 | 2 +- .../main/ets/entryability/EntryAbility.ets | 28 ++++++++++++------- .../src/main/ets/pages/Index.ets | 2 +- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets index ab31541..5ee2b40 100644 --- a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets +++ b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets @@ -76,11 +76,11 @@ export class WindowUtil { // Get status bar height and indicator height. private static setAvoidArea(data: window.Window, type: window.AvoidAreaType, area: window.AvoidArea) { - const context: UIContext = data.getUIContext(); + const context: UIContext | undefined = AppStorage.get(Constants.KEY_UI_CONTEXT); if (type === window.AvoidAreaType.TYPE_SYSTEM) { - AppStorage.setOrCreate(Constants.KEY_STATUS_BAR_HEIGHT, context.px2vp(area.topRect.height)); + AppStorage.setOrCreate(Constants.KEY_STATUS_BAR_HEIGHT, context?.px2vp(area.topRect.height)); } else if (type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { - AppStorage.setOrCreate(Constants.KEY_NAV_INDICATOR_HEIGHT, context.px2vp(area.bottomRect.height)); + AppStorage.setOrCreate(Constants.KEY_NAV_INDICATOR_HEIGHT, context?.px2vp(area.bottomRect.height)); } } } \ No newline at end of file diff --git a/webprerendersample/oh-package.json5 b/webprerendersample/oh-package.json5 index c84bc8b..2a4c88b 100644 --- a/webprerendersample/oh-package.json5 +++ b/webprerendersample/oh-package.json5 @@ -6,6 +6,6 @@ "author": "", "license": "", "dependencies": { - "@ohos_samples/webprerenderlibrary": "file:../webprerenderlibrary" + "webprerenderlibrary": "file:../webprerenderlibrary" } } \ No newline at end of file diff --git a/webprerendersample/src/main/ets/entryability/EntryAbility.ets b/webprerendersample/src/main/ets/entryability/EntryAbility.ets index e7d674c..3bb21e2 100644 --- a/webprerendersample/src/main/ets/entryability/EntryAbility.ets +++ b/webprerendersample/src/main/ets/entryability/EntryAbility.ets @@ -15,44 +15,52 @@ import { ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { WebPrerenderController } from '@ohos_samples/webprerenderlibrary'; +import { WebPrerenderController } from 'webprerenderlibrary'; + +const TAG = '[WebPrerenderSampleAbility]'; export default class WebPrerenderSampleAbility extends UIAbility { onCreate(): void { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(0x0000, TAG, '%{public}s', 'Ability onCreate'); + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (error) { + const err: BusinessError = error as BusinessError; + hilog.error(0x0000, TAG, '%{public}s', `Set colorMode failed: ${err.code}, ${err.message}`); + } } onDestroy(): void { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + hilog.info(0x0000, TAG, '%{public}s', 'Ability onDestroy'); } onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageCreate'); windowStage.loadContent('pages/Index', (err) => { if (err.code) { - hilog.error(0x0000, 'testTag', '%{public}s', `Failed to load the content. Cause: ${err.code}`); + hilog.error(0x0000, TAG, '%{public}s', `Failed to load the content. Cause: ${err.code}`); return; } WebPrerenderController.initWindowConfig(windowStage); - hilog.info(0x0000, 'testTag', '%{public}s', `Succeed in loading the content.`); + hilog.info(0x0000, TAG, '%{public}s', `Succeed in loading the content.`); }); } onWindowStageDestroy(): void { // Main window is destroyed, release UI related resources - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageDestroy'); } onForeground(): void { // Ability has brought to foreground - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + hilog.info(0x0000, TAG, '%{public}s', 'Ability onForeground'); } onBackground(): void { // Ability has back to background - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + hilog.info(0x0000, TAG, '%{public}s', 'Ability onBackground'); } } \ No newline at end of file diff --git a/webprerendersample/src/main/ets/pages/Index.ets b/webprerendersample/src/main/ets/pages/Index.ets index cec612b..c9a0430 100644 --- a/webprerendersample/src/main/ets/pages/Index.ets +++ b/webprerendersample/src/main/ets/pages/Index.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { WebPreRenderComponent } from '@ohos_samples/webprerenderlibrary'; +import { WebPreRenderComponent } from 'webprerenderlibrary'; @Entry @Component -- Gitee From 0bb7974438a7dea7692f36cbc449c285ccf397ff Mon Sep 17 00:00:00 2001 From: EasyGuohf <163991322+EasyGuohf@users.noreply.github.com> Date: Tue, 12 Aug 2025 20:42:06 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BE=9D=E8=B5=96=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webprerendersample/oh-package.json5 | 2 +- webprerendersample/src/main/ets/entryability/EntryAbility.ets | 2 +- webprerendersample/src/main/ets/pages/Index.ets | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/webprerendersample/oh-package.json5 b/webprerendersample/oh-package.json5 index 2a4c88b..c84bc8b 100644 --- a/webprerendersample/oh-package.json5 +++ b/webprerendersample/oh-package.json5 @@ -6,6 +6,6 @@ "author": "", "license": "", "dependencies": { - "webprerenderlibrary": "file:../webprerenderlibrary" + "@ohos_samples/webprerenderlibrary": "file:../webprerenderlibrary" } } \ No newline at end of file diff --git a/webprerendersample/src/main/ets/entryability/EntryAbility.ets b/webprerendersample/src/main/ets/entryability/EntryAbility.ets index 3bb21e2..7f65db3 100644 --- a/webprerendersample/src/main/ets/entryability/EntryAbility.ets +++ b/webprerendersample/src/main/ets/entryability/EntryAbility.ets @@ -17,7 +17,7 @@ import { ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { WebPrerenderController } from 'webprerenderlibrary'; +import { WebPrerenderController } from '@ohos_samples/webprerenderlibrary'; const TAG = '[WebPrerenderSampleAbility]'; diff --git a/webprerendersample/src/main/ets/pages/Index.ets b/webprerendersample/src/main/ets/pages/Index.ets index c9a0430..cec612b 100644 --- a/webprerendersample/src/main/ets/pages/Index.ets +++ b/webprerendersample/src/main/ets/pages/Index.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { WebPreRenderComponent } from 'webprerenderlibrary'; +import { WebPreRenderComponent } from '@ohos_samples/webprerenderlibrary'; @Entry @Component -- Gitee