From 03c88348ef242076ca384da61175943c4b8ebf8d Mon Sep 17 00:00:00 2001 From: wpp <58198665+879356503@users.noreply.github.com> Date: Tue, 22 Apr 2025 22:19:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/entryability/EntryAbility.ets | 50 +++++-------------- 1 file changed, 13 insertions(+), 37 deletions(-) diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 024c30e..703915b 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; import { display, window } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { BusinessError } from '@kit.BasicServicesKit'; @@ -21,10 +21,9 @@ import { BusinessError } from '@kit.BasicServicesKit'; const TAG: string = '[EntryAbility]'; export default class EntryAbility extends UIAbility { - private windowObj?: window.Window; private curBp: string = ''; - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + onCreate(): void { hilog.info(0x0000, TAG, '%{public}s', 'Ability onCreate'); this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); } @@ -44,11 +43,20 @@ export default class EntryAbility extends UIAbility { avoidArea = windowObj.getWindowAvoidArea(type); let topRectHeight = avoidArea.topRect.height; AppStorage.setOrCreate('topRectHeight', topRectHeight); - this.windowObj = windowObj; this.updateBreakpoint(windowObj.getWindowProperties().windowRect.width); + windowObj.on('windowSizeChange', (windowSize) => { this.updateBreakpoint(windowSize.width); }); + + windowObj.setWindowLayoutFullScreen(true).then(() => { + hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in setting the window layout to full-screen mode.'); + }).catch((err: BusinessError) => { + hilog.error(0x0000, TAG, 'Failed to set the window layout to full-screen mode. Cause: %{public}s', + `the code is ${err.code}, the message is ${err.message}`); + }); + + AppStorage.setOrCreate('windowClass', windowObj); } catch (error) { const err: BusinessError = error as BusinessError; hilog.error(0x0000, TAG, 'get window info catch err: Cause: %{public}s', @@ -63,21 +71,7 @@ export default class EntryAbility extends UIAbility { `the code is ${err.code}, the message is ${err.message}`); return; } - try { - this.setWindowClass(windowStage); - hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in loading the content.'); - let windowClass: window.Window = windowStage.getMainWindowSync(); - let isLayoutFullScreen = true; - windowClass.setWindowLayoutFullScreen(isLayoutFullScreen).then(() => { - hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in setting the window layout to full-screen mode.'); - }).catch((err: BusinessError) => { - hilog.error(0x0000, TAG, 'Failed to set the window layout to full-screen mode. Cause: %{public}s', - `the code is ${err.code}, the message is ${err.message}`); - }); - } catch (err) { - hilog.error(0x0000, TAG, - `onWindowStageCreate failed. code: ${(err as BusinessError).code}, message: ${(err as BusinessError).message}`); - } + hilog.info(0x0000, TAG, 'Succeed in loading the content.'); }); } @@ -117,22 +111,4 @@ export default class EntryAbility extends UIAbility { `An unexpected error occurred. Code: ${err.code}, message: ${err.message}`); } } - - private setWindowClass(windowStage: window.WindowStage): void { - try { - windowStage.getMainWindow((err: BusinessError, data) => { - const errCode: number = err.code; - if (errCode) { - hilog.error(0x0000, TAG, 'Failed to get main window. Cause: %{public}s', - `the code is ${err.code}, the message is ${err.message}`); - return; - } - AppStorage.setOrCreate('windowClass', data); - }) - } catch (error) { - const err: BusinessError = error as BusinessError; - hilog.error(0x0000, TAG, '%{public}s', - `An unexpected error occurred. Code: ${err.code}, message: ${err.message}`); - } - } } -- Gitee