diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 0da01c684f39efe375cf9d8366b042154af4b7e0..595a7437cb5ce47ffe4883bfdded99d79abbfd3a 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -67,12 +67,12 @@ export default class EntryAbility extends UIAbility { // Main window is created, set main page for this ability hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageCreate'); windowStage.getMainWindow().then((windowObj: window.Window) => { - let type: window.AvoidAreaType = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; - let avoidArea: window.AvoidArea = windowObj.getWindowAvoidArea(type); - let bottomRectHeight: number = avoidArea.bottomRect.height; - AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight); - this.updateBreakpoint(windowObj.getWindowProperties().windowRect.width); try { + let type: window.AvoidAreaType = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; + let avoidArea: window.AvoidArea = windowObj.getWindowAvoidArea(type); + let bottomRectHeight: number = avoidArea.bottomRect.height; + AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight); + this.updateBreakpoint(windowObj.getWindowProperties().windowRect.width); windowObj.on('windowSizeChange', (windowSize) => { this.updateBreakpoint(windowSize.width); }); @@ -92,7 +92,9 @@ export default class EntryAbility extends UIAbility { hilog.error(0x0000, TAG, '%{public}s', `onWindowStageCreate failed. Cause code: ${error.code}, message: ${error.message}`); } - }) + }).catch((err: BusinessError) => { + hilog.error(0x0000, TAG, `Failed to get main window. Cause:`, err.message); + }); } onWindowStageDestroy(): void {