diff --git a/product/phone/src/main/ets/phoneability/PhoneAbility.ets b/product/phone/src/main/ets/phoneability/PhoneAbility.ets index 839d7a536d244ec214f4feb4abcd2da6bf61459a..e3c2c88c7488d007548e897a5b28438e6df7ade5 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 {