diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 32c67f8bce4dc645d25ed0cdd6948613521948f7..98359fc01157b5505f5527efae3df142eda6fbe6 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -65,52 +65,48 @@ export default class EntryAbility extends UIAbility { } onWindowStageCreate(windowStage: window.WindowStage): void { - windowStage.getMainWindow().then((windowObj: window.Window) => { - try { - let type = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; - let avoidArea = windowObj.getWindowAvoidArea(type); - let bottomRectHeight = avoidArea.bottomRect.height; - AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight); - type = window.AvoidAreaType.TYPE_SYSTEM; - avoidArea = windowObj.getWindowAvoidArea(type); - let topRectHeight = avoidArea.topRect.height; - AppStorage.setOrCreate('topRectHeight', topRectHeight); - this.updateBreakpoint(windowObj.getWindowProperties().windowRect.width); - windowObj.on('windowSizeChange', (windowSize) => { - this.updateBreakpoint(windowSize.width); - }); - } catch (err) { - hilog.error(0x0000, 'testTag', `Set window properties err. Cause: ${err.code}`); - } - }).catch((err: BusinessError) => { - hilog.error(0x0000, 'testTag', `Failed to get main window. Cause:`, err.message); - }); // Main window is created, set main page for this ability hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - let context = this.context; - let resourceManager: resourceManager.ResourceManager = context.resourceManager; + let resourceManager: resourceManager.ResourceManager = this.context.resourceManager; AppStorage.setOrCreate('resourceManager', resourceManager); - windowStage.loadContent('pages/Index', (err, data) => { - try { - createNWeb(ResourceUtil.getRawFileStringByKey(getContext(this) as common.UIAbilityContext, - ConfigMapKey.GALLERY_URL), windowStage.getMainWindowSync().getUIContext()); - if (err.code) { - hilog.error(0x0000, 'testTag', 'Failed to load the content.'); - return; - } - hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.', JSON.stringify(data) ?? ''); - let windowClass: window.Window = windowStage.getMainWindowSync(); - let isLayoutFullScreen = true; - windowClass.setWindowLayoutFullScreen(isLayoutFullScreen).then(() => { - hilog.info(0x0000, 'testTag', '%{public}s', 'Succeeded in setting the window layout to full-screen mode.'); - }).catch(() => { - hilog.error(0x0000, 'testTag', '%{public}s', 'Failed to set the window layout to full-screen mode.'); - }); - } catch (error) { - hilog.error(0x0000, 'testTag', '%{public}s', - `onWindowStageCreate failed. Cause code: ${error.code}, message: ${error.message}`); + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', '%{public}s', `Failed to load the content. Cause: ${err.code}`); + return; } + hilog.info(0x0000, 'testTag', '%{public}s', `Succeed in loading the content.`); + + windowStage.getMainWindow().then((windowObj: window.Window) => { + try { + let type = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; + let avoidArea = windowObj.getWindowAvoidArea(type); + let bottomRectHeight = avoidArea.bottomRect.height; + AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight); + type = window.AvoidAreaType.TYPE_SYSTEM; + avoidArea = windowObj.getWindowAvoidArea(type); + let topRectHeight = avoidArea.topRect.height; + AppStorage.setOrCreate('topRectHeight', topRectHeight); + this.updateBreakpoint(windowObj.getWindowProperties().windowRect.width); + + windowObj.on('windowSizeChange', (windowSize) => { + this.updateBreakpoint(windowSize.width); + }); + + windowObj.setWindowLayoutFullScreen(true).then(() => { + hilog.info(0x0000, 'testTag', '%{public}s', 'Succeeded in setting the window layout to full-screen mode.'); + }).catch(() => { + hilog.error(0x0000, 'testTag', '%{public}s', 'Failed to set the window layout to full-screen mode.'); + }); + + createNWeb(ResourceUtil.getRawFileStringByKey(getContext(this) as common.UIAbilityContext, + ConfigMapKey.GALLERY_URL), windowObj.getUIContext()); + } catch (err) { + hilog.error(0x0000, 'testTag', `Set window properties err. Cause: ${err.code}`); + } + }).catch((err: BusinessError) => { + hilog.error(0x0000, 'testTag', `Failed to get main window. Cause:`, err.message); + }); }); }