From 6cc2498e644f0722d8b1d78cb41fd09521c5e48f Mon Sep 17 00:00:00 2001 From: rekirt Date: Tue, 8 Apr 2025 17:28:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9md=E6=96=87=E6=A1=A3=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86throw=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=9C=AA=E6=B7=BB=E5=8A=A0try=20catch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: rekirt --- README.en.md | 3 +- README.md | 5 +- .../main/ets/entryability/EntryAbility.ets | 56 +++++++++++-------- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/README.en.md b/README.en.md index 128bc19..6f90868 100644 --- a/README.en.md +++ b/README.en.md @@ -45,8 +45,7 @@ You can view the page effect in the Previewer of DevEco Studio or on the device. │ │ ├──Index.ets // Home page │ │ └──TableAdaptiveExtensionIndex.ets // Implementation of tables that extend and adapt based on the screen size. │ └──utils -│ ├──BreakpointType.ets // Breakpoint types -│ └──Logger.ets // Logging utility +│ └──BreakpointType.ets // Breakpoint types └──entry/src/main/resources // Resources of the app ``` diff --git a/README.md b/README.md index 9994d1d..08cfc50 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,8 @@ │ │ ├──DoubleTabAdaptiveCenteringIndex.ets // 双tab自适应居中页 │ │ ├──Index.ets // 首页 │ │ └──TableAdaptiveExtensionIndex.ets // 表格自适应延伸页 -│ └──utils -│ ├──BreakpointType.ets // 断点类型 -│ └──Logger.ets // 日志 +│ └──utils +│ └──BreakpointType.ets // 断点类型 └──entry/src/main/resources // 应用资源目录 ``` diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 205d431..24f1044 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -25,7 +25,11 @@ export default class EntryAbility extends UIAbility { onCreate(): void { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); AppStorage.setOrCreate('systemColorMode', this.context.config.colorMode); - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(0x0000, 'testTag', '%{public}s', 'setColorMode fail. error code: ' + err.code); + } } onDestroy(): void { @@ -37,31 +41,37 @@ export default class EntryAbility extends UIAbility { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); windowStage.getMainWindow().then((data: window.Window) => { let type = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; - let avoidArea = data.getWindowAvoidArea(type); - let bottomRectHeight = avoidArea.bottomRect.height; - AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight); - type = window.AvoidAreaType.TYPE_SYSTEM; - avoidArea = data.getWindowAvoidArea(type); - let topRectHeight = avoidArea.topRect.height; - AppStorage.setOrCreate('topRectHeight', topRectHeight); - this.windowObj = data; - this.updateBreakpoint(this.windowObj.getWindowProperties().windowRect.width); - this.windowObj.on('windowSizeChange', (windowSize: window.Size) => { - this.updateBreakpoint(windowSize.width); - }); - }) + try { + let avoidArea = data.getWindowAvoidArea(type); + let bottomRectHeight = avoidArea.bottomRect.height; + AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight); + type = window.AvoidAreaType.TYPE_SYSTEM; + avoidArea = data.getWindowAvoidArea(type); + let topRectHeight = avoidArea.topRect.height; + AppStorage.setOrCreate('topRectHeight', topRectHeight); + this.windowObj = data; + this.updateBreakpoint(this.windowObj.getWindowProperties().windowRect.width); + this.windowObj.on('windowSizeChange', (windowSize: window.Size) => { + this.updateBreakpoint(windowSize.width); + }); + } catch (err) { + hilog.error(0x0000, 'testTag', '%{public}s', 'config main window fail. Cause: ' + err.message); + } + }); windowStage.loadContent('pages/Index', (err) => { if (err.code) { - hilog.error(0x0000, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err.code) ?? ''); + hilog.error(0x0000, 'testTag', '%{public}s', 'Failed to load the content. Cause: ' + err.code); return; } - let windowClass: window.Window = windowStage.getMainWindowSync(); - let isLayoutFullScreen = true; - windowClass.setWindowLayoutFullScreen(isLayoutFullScreen).then(() => { - hilog.info(0x0000, 'testTag', 'Succeeded in setting the window layout to full-screen mode.'); - }).catch((err: BusinessError) => { - hilog.error(0x0000, 'Failed to set the window layout to full-screen mode.', JSON.stringify(err.code)); - }); + try { + 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 (err) { + hilog.error(0x0000, 'testTag', '%{public}s', 'Failed to set the window layout to full-screen mode. ' + err.code); + } }); } @@ -78,7 +88,7 @@ export default class EntryAbility extends UIAbility { } AppStorage.setOrCreate('breakPoint', curBp); } catch (exception) { - hilog.error(0x0000, 'testTag', `UpdateBreakpoint fail, error code: ${(exception as BusinessError).code}`); + hilog.error(0x0000, 'testTag', '%{public}s', `UpdateBreakpoint fail, error code: ${(exception as BusinessError).code}`); } } -- Gitee