From c5b4b1a36b9bf67a2531b9d503f0bc25ee82bb6d Mon Sep 17 00:00:00 2001 From: EasyGuohf <163991322+EasyGuohf@users.noreply.github.com> Date: Thu, 18 Dec 2025 20:29:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AE=89=E5=85=A8=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/WebPrerenderController.ets | 4 ++ .../src/main/ets/common/ResourceUtil.ets | 4 +- .../src/main/ets/common/utils/WindowUtil.ets | 49 +++++++++++-------- .../main/ets/entryability/EntryAbility.ets | 3 +- 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/webprerenderlibrary/src/main/ets/WebPrerenderController.ets b/webprerenderlibrary/src/main/ets/WebPrerenderController.ets index ef1591d..7c2591d 100644 --- a/webprerenderlibrary/src/main/ets/WebPrerenderController.ets +++ b/webprerenderlibrary/src/main/ets/WebPrerenderController.ets @@ -19,4 +19,8 @@ export class WebPrerenderController { public static initWindowConfig(windowStage: window.WindowStage): void { WindowUtil.initialize(windowStage); } + + public static releaseWindowConfig(): void { + WindowUtil.unregisterBreakPoint(); + } } \ No newline at end of file diff --git a/webprerenderlibrary/src/main/ets/common/ResourceUtil.ets b/webprerenderlibrary/src/main/ets/common/ResourceUtil.ets index f24e0a5..a6d3499 100644 --- a/webprerenderlibrary/src/main/ets/common/ResourceUtil.ets +++ b/webprerenderlibrary/src/main/ets/common/ResourceUtil.ets @@ -76,7 +76,9 @@ export class ResourceUtil { return linkUrl; } return ''; - } catch (error) { + } catch (err) { + const error = err as BusinessError; + Logger.error('ResourceUtil', `Get RawFile failed. Cause code: ${error.code}, message: ${error.message}`); return ''; } } diff --git a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets index 9aea7d3..1a8a1f7 100644 --- a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets +++ b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets @@ -25,6 +25,12 @@ const TAG: string = '[WindowUtil]'; export class WindowUtil { private static windowClass: window.Window; + private static windowSizeChangeCallBack: () => void = () => { + BreakpointSystem.getInstance().onWindowSizeChange(WindowUtil.windowClass); + }; + private static avoidAreaChangeCallBack: (avoidAreaOption: window.AvoidAreaOptions) => void = (avoidAreaOption) => { + WindowUtil.setAvoidArea(WindowUtil.windowClass,avoidAreaOption.type, avoidAreaOption.area); + }; public static initialize(windowStage: window.WindowStage) { try { @@ -41,18 +47,10 @@ export class WindowUtil { } public static requestFullScreen(windowClass: window.Window): void { - // Realize the immersive effect. - try { - const promise: Promise = windowClass.setWindowLayoutFullScreen(true); - promise.then(() => { - Logger.info(TAG, 'Succeeded in setting the window layout to full-screen mode.'); - }).catch((err: BusinessError) => { - Logger.error(TAG, - `Failed to set the window layout to full-screen mode. Cause: ${err.code}, ${err.message}`); - }); - } catch { - Logger.error(TAG, 'Failed to set the window layout to full-screen mode. '); - } + windowClass.setWindowLayoutFullScreen(true).catch((err: BusinessError) => { + Logger.error(TAG, + `Failed to set the window layout to full-screen mode. Cause: ${err.code}, ${err.message}`); + }); } public static registerBreakPoint(data: window.Window) { @@ -63,10 +61,8 @@ export class WindowUtil { data.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR); WindowUtil.setAvoidArea(data, window.AvoidAreaType.TYPE_SYSTEM, systemAvoidArea); WindowUtil.setAvoidArea(data, window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR, navIndicatorAvoidArea); - data.on('windowSizeChange', () => BreakpointSystem.getInstance().onWindowSizeChange(data)); - data.on('avoidAreaChange', (avoidAreaOption) => { - WindowUtil.setAvoidArea(data, avoidAreaOption.type, avoidAreaOption.area); - }); + data.on('windowSizeChange', WindowUtil.windowSizeChangeCallBack); + data.on('avoidAreaChange', WindowUtil.avoidAreaChangeCallBack); } catch (err) { const error = err as BusinessError; Logger.error(TAG, @@ -74,13 +70,26 @@ export class WindowUtil { } } + public static unregisterBreakPoint() { + try { + WindowUtil.windowClass.off('windowSizeChange', WindowUtil.windowSizeChangeCallBack); + WindowUtil.windowClass.off('avoidAreaChange', WindowUtil.avoidAreaChangeCallBack); + } catch (error) { + const err: BusinessError = error as BusinessError; + Logger.error(TAG, + `Failed to unregister the windowSizeChange or the WindowAvoidArea. Cause: ${err.code}, ${err.message}`); + } + } + // Get status bar height and indicator height. private static setAvoidArea(data: window.Window, type: window.AvoidAreaType, area: window.AvoidArea) { 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)); - } else if (type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { - AppStorage.setOrCreate(Constants.KEY_NAV_INDICATOR_HEIGHT, context?.px2vp(area.bottomRect.height)); + if(context){ + if (type === window.AvoidAreaType.TYPE_SYSTEM) { + 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)); + } } } } \ 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 5e2d77f..cadda43 100644 --- a/webprerendersample/src/main/ets/entryability/EntryAbility.ets +++ b/webprerendersample/src/main/ets/entryability/EntryAbility.ets @@ -49,8 +49,9 @@ export default class WebPrerenderSampleAbility extends UIAbility { } onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources Logger.info(TAG, 'Ability onWindowStageDestroy'); + // Main window is destroyed, release UI related resources + WebPrerenderController.releaseWindowConfig(); } onForeground(): void { -- Gitee From f92648787e0c9aab768ab953986bb9116c3855a9 Mon Sep 17 00:00:00 2001 From: EasyGuohf <163991322+EasyGuohf@users.noreply.github.com> Date: Fri, 19 Dec 2025 11:45:53 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AE=89=E5=85=A8=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webprerendersample/src/main/ets/entryability/EntryAbility.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webprerendersample/src/main/ets/entryability/EntryAbility.ets b/webprerendersample/src/main/ets/entryability/EntryAbility.ets index cadda43..e94e907 100644 --- a/webprerendersample/src/main/ets/entryability/EntryAbility.ets +++ b/webprerendersample/src/main/ets/entryability/EntryAbility.ets @@ -39,7 +39,7 @@ export default class WebPrerenderSampleAbility extends UIAbility { // Main window is created, set main page for this ability Logger.info(TAG, 'Ability onWindowStageCreate'); windowStage.loadContent('pages/Index', (err) => { - if (err.code) { + if (err?.code) { Logger.error(TAG, `Failed to load the content. Cause: ${err.code}.`); return; } -- Gitee