From 0fb0c6a4b704abbdd835ee74581d2efb64f2673c Mon Sep 17 00:00:00 2001 From: dhf_fanr <1511447814@qq.com> Date: Tue, 16 Sep 2025 14:50:09 +0800 Subject: [PATCH] =?UTF-8?q?IDE=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/phoneability/PhoneAbility.ets | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/product/phone/src/main/ets/phoneability/PhoneAbility.ets b/product/phone/src/main/ets/phoneability/PhoneAbility.ets index 839d7a5..e3c2c88 100755 --- a/product/phone/src/main/ets/phoneability/PhoneAbility.ets +++ b/product/phone/src/main/ets/phoneability/PhoneAbility.ets @@ -21,6 +21,7 @@ import { BaseConstants, BreakpointConstants } from '@ohos/commons/Index'; export default class PhoneAbility extends UIAbility { private windowObj?: window.Window; + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); } @@ -35,7 +36,12 @@ export default class PhoneAbility extends UIAbility { windowStage.getMainWindow((err: BusinessError, data) => { this.windowObj = data; - this.updateBreakpoint(this.windowObj.getWindowProperties().windowRect.width); + try { + this.updateBreakpoint(this.windowObj.getWindowProperties().windowRect.width); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x00, 'PhoneAbility', `updateBreakpoint failed, code = ${err.code}, message = ${err.message}`); + } this.windowObj.on('windowSizeChange', (windowSize: window.Size) => { this.updateBreakpoint(windowSize.width); }) @@ -44,7 +50,9 @@ export default class PhoneAbility extends UIAbility { return; } if (deviceInfo.deviceType !== BaseConstants.DEVICE_2IN1) { - data.setWindowLayoutFullScreen(true); + data.setWindowLayoutFullScreen(true).catch((error: BusinessError) => { + hilog.error(0x00, 'PhoneAbility', `openSync failed, code = ${error.code}, message = ${error.message}`); + }); } }) @@ -56,17 +64,24 @@ export default class PhoneAbility extends UIAbility { hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); }); } - private updateBreakpoint(windowWidth: number) :void{ - let windowWidthVp = windowWidth / display.getDefaultDisplaySync().densityPixels; - let curBp: string = ''; - if (windowWidthVp < BreakpointConstants.BREAKPOINT_SCOPE[2]) { - curBp = BreakpointConstants.BREAKPOINT_SM; - } else if (windowWidthVp < BreakpointConstants.BREAKPOINT_SCOPE[3]) { - curBp = BreakpointConstants.BREAKPOINT_MD; - } else { - curBp = BreakpointConstants.BREAKPOINT_LG; + + private updateBreakpoint(windowWidth: number): void { + try { + let windowWidthVp = windowWidth / display.getDefaultDisplaySync().densityPixels; + let curBp: string = ''; + if (windowWidthVp < BreakpointConstants.BREAKPOINT_SCOPE[2]) { + curBp = BreakpointConstants.BREAKPOINT_SM; + } else if (windowWidthVp < BreakpointConstants.BREAKPOINT_SCOPE[3]) { + curBp = BreakpointConstants.BREAKPOINT_MD; + } else { + curBp = BreakpointConstants.BREAKPOINT_LG; + } + AppStorage.setOrCreate('currentBreakpoint', curBp); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x00, 'PhoneAbility', `getDefaultDisplaySync failed, code = ${err.code}, message = ${err.message}`); } - AppStorage.setOrCreate('currentBreakpoint', curBp); + } onWindowStageDestroy(): void { -- Gitee