From f3dc397f505fadceb1f65b64ab0a553559e3da3c Mon Sep 17 00:00:00 2001 From: wpp <58198665+879356503@users.noreply.github.com> Date: Wed, 23 Apr 2025 09:45:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/entryability/EntryAbility.ets | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 32c67f8..53491b8 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -76,9 +76,16 @@ export default class EntryAbility extends UIAbility { 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.'); + }); } catch (err) { hilog.error(0x0000, 'testTag', `Set window properties err. Cause: ${err.code}`); } @@ -88,10 +95,9 @@ export default class EntryAbility extends UIAbility { // 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) => { + windowStage.loadContent('pages/Index', (err) => { try { createNWeb(ResourceUtil.getRawFileStringByKey(getContext(this) as common.UIAbilityContext, ConfigMapKey.GALLERY_URL), windowStage.getMainWindowSync().getUIContext()); @@ -99,14 +105,7 @@ export default class EntryAbility extends UIAbility { 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.'); - }); + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); } catch (error) { hilog.error(0x0000, 'testTag', '%{public}s', `onWindowStageCreate failed. Cause code: ${error.code}, message: ${error.message}`); -- Gitee From bac453a702a7da5db0f92e072e35d409084d5a94 Mon Sep 17 00:00:00 2001 From: wpp <58198665+879356503@users.noreply.github.com> Date: Wed, 23 Apr 2025 09:57:53 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/entryability/EntryAbility.ets | 73 +++++++++---------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 53491b8..98359fc 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -65,51 +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); - }); - - 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.'); - }); - } 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 resourceManager: resourceManager.ResourceManager = this.context.resourceManager; AppStorage.setOrCreate('resourceManager', resourceManager); windowStage.loadContent('pages/Index', (err) => { - 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.'); - } catch (error) { - hilog.error(0x0000, 'testTag', '%{public}s', - `onWindowStageCreate failed. Cause code: ${error.code}, message: ${error.message}`); + 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); + }); }); } -- Gitee