diff --git a/entry/src/main/ets/common/Utils.ets b/entry/src/main/ets/common/Utils.ets index facd5c084f9c40876d2e492a1b2c669309412dfd..cb4ab5e433a7c6e9c389df85e39f09fcf98952cd 100644 --- a/entry/src/main/ets/common/Utils.ets +++ b/entry/src/main/ets/common/Utils.ets @@ -16,9 +16,9 @@ import { Constants } from './Constants'; export class BreakpointType { - sm: T; - md: T; - lg: T; + private sm: T; + private md: T; + private lg: T; constructor(sm: T, md: T, lg: T) { this.sm = sm; diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index fd73a080cf489724c646439cdbfbc688f7f53143..0c9ff5be3d4856dedac6fcb999ea32f5b1d602ef 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -27,18 +27,22 @@ export default class EntryAbility extends UIAbility { private curBp: string = ''; private updateBreakpoint(windowWidth: number): void { - let windowWidthVp = windowWidth / display.getDefaultDisplaySync().densityPixels; - let newBp: string = ''; - if (windowWidthVp < 600) { - newBp = Constants.BREAK_POINT_SM; - } else if (windowWidthVp < 840) { - newBp = Constants.BREAK_POINT_MD; - } else { - newBp = Constants.BREAK_POINT_LG; - } - if (this.curBp !== newBp) { - this.curBp = newBp; - AppStorage.setOrCreate('currentBreakpoint', this.curBp); + try { + let windowWidthVp: number = windowWidth / display.getDefaultDisplaySync().densityPixels; + let newBp: string = ''; + if (windowWidthVp < 600) { + newBp = Constants.BREAK_POINT_SM; + } else if (windowWidthVp < 840) { + newBp = Constants.BREAK_POINT_MD; + } else { + newBp = Constants.BREAK_POINT_LG; + } + if (this.curBp !== newBp) { + this.curBp = newBp; + AppStorage.setOrCreate('currentBreakpoint', this.curBp); + } + } catch (error) { + hilog.error(0x0000, TAG, 'updateBreakpoint catch err:', JSON.stringify(error) ?? ''); } } @@ -84,7 +88,7 @@ export default class EntryAbility extends UIAbility { AppStorage.setOrCreate('resourceManager', resourceManager); windowStage.loadContent('pages/Index', (err, data) => { if (err.code) { - hilog.error(0x0000, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + hilog.error(0x0000, TAG, 'Failed to load the content. Cause:', JSON.stringify(err) ?? ''); return; } hilog.info(0x0000, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); @@ -93,7 +97,8 @@ export default class EntryAbility extends UIAbility { windowClass.setWindowLayoutFullScreen(isLayoutFullScreen).then(() => { hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in setting the window layout to full-screen mode'); }).catch((err: BusinessError) => { - hilog.error(0x0000, TAG, 'Failed to set the window layout to full-screen mode. Cause:', JSON.stringify(err) ?? ''); + hilog.error(0x0000, TAG, 'Failed to set the window layout to full-screen mode. Cause:', + JSON.stringify(err) ?? ''); }); }); }