diff --git a/README.en.md b/README.en.md index 099e8507a05431dd0200d4e1ae6012e5776dc2b2..6b129cf7c70cffeb1b2066dba02c0c1432ec05f9 100644 --- a/README.en.md +++ b/README.en.md @@ -19,8 +19,11 @@ Instructions: ``` ├──entry/src/main/ets/ -│ ├──common/constant -│ │ └──CommonConstants.ets // Common constant class +│ ├──common +│ │ ├──constants +│ │ │ └─CommonConstants.ets // Common constant class +│ │ └──utils +│ │ └──Utils.ets // Utils class │ ├──entryability │ │ └──EntryAbility.ets // Entry point class │ ├──page diff --git a/README.md b/README.md index 0165fd886c734adf46bf3be2c70170ec2507dc68..4e5a219c69d6166eaa9f2056f1fc0c9baa4a1c3d 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,11 @@ ``` ├──entry/src/main/ets/ -│ ├──common/constant -│ │ └──CommonConstants.ets // 公共常量类 +│ ├──common +│ │ ├──constants +│ │ │ └─CommonConstants.ets // 公共常量类 +│ │ └──utils +│ │ └──Utils.ets // 工具类 │ ├──entryability │ │ └──EntryAbility.ets // 程序入口类 │ ├──page diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 9deb8c937762bd7c054fbf4a8c379d6b82b25671..83ad01fb4c98fa7fce1c18cee711165784718f7c 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -38,15 +38,19 @@ export default class EntryAbility extends UIAbility { AppStorage.setOrCreate('currentBreakpoint', this.curBp); } } catch (exception) { - hilog.error(0x0000, 'testTag', - `UpdateBreakpoint fail, error code: ${JSON.stringify((exception as BusinessError).code)}`); + hilog.error(0x0000, 'testTag', '%{public}s', + `UpdateBreakpoint fail, error code: ${(exception as BusinessError).code}`); } } 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 { @@ -56,17 +60,21 @@ export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage): void { windowStage.getMainWindow().then((windowObj: window.Window) => { 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); - }) + try { + 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', '%{public}s', `config window fail. Cause: ${err.code}`); + } }); // Main window is created, set main page for this ability hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); @@ -75,16 +83,18 @@ export default class EntryAbility extends UIAbility { AppStorage.setOrCreate('resourceManager', resourceManager); 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}`); + } }); }