From 4531dc338abb069c1a256e62eb4ee30aa28b1522 Mon Sep 17 00:00:00 2001 From: li-li-wang Date: Thu, 12 Jun 2025 16:23:19 +0800 Subject: [PATCH] =?UTF-8?q?API=E6=9C=AA=E4=BD=BF=E7=94=A8try-catch?= =?UTF-8?q?=E6=88=96.catch=E6=8D=95=E8=8E=B7=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-li-wang --- .../src/main/ets/pages/securityToast.ets | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/permissionmanager/src/main/ets/pages/securityToast.ets b/permissionmanager/src/main/ets/pages/securityToast.ets index b9a3239..0dd3eb3 100644 --- a/permissionmanager/src/main/ets/pages/securityToast.ets +++ b/permissionmanager/src/main/ets/pages/securityToast.ets @@ -59,14 +59,23 @@ struct SecurityToast { getWinAvoidArea() { let type = window.AvoidAreaType.TYPE_SYSTEM; - let avoidArea = this.win?.getWindowAvoidArea(type); - this.topRectHeight = avoidArea.topRect.height; + try { + let avoidArea = this.win?.getWindowAvoidArea(type); + this.topRectHeight = avoidArea.topRect.height; + } catch (error) { + Log.error(`Failed to obtain the area. Cause code: ${error.code}, message: ${error.message}`); + }; } aboutToAppear(): void { Log.info('onAboutToAppear'); - this.rotationInit = display.getDefaultDisplaySync().orientation; - this.densityDPIInit = display.getDefaultDisplaySync().densityDPI; + try { + let dis = display.getDefaultDisplaySync(); + this.rotationInit = dis.orientation; + this.densityDPIInit = dis.densityDPI; + } catch (error) { + Log.error(`Failed to get default display. Cause code: ${error.code}, message: ${error.message}`); + }; this.setPosition = this.want.parameters['ohos.toast.position'] ?? false; this.positionY = this.setPosition ? Constants.TOAST_POSITION_Y_UP : Constants.TOAST_POSITION_Y_UNDER; this.setOffset = this.want.parameters['ohos.toast.offset'] ?? Constants.TOAST_ANIMATION_OFFSET; @@ -100,7 +109,7 @@ struct SecurityToast { screenMonitor() { try { display.on('foldStatusChange', (data: display.FoldStatus) => { - Log.info(`Listening enabled. Data: ${JSON.stringify(data)}`); + Log.info(`Listening foldStatusChange. Data: ${JSON.stringify(data)}`); this.win?.destroyWindow(); }); } catch (exception) { @@ -109,7 +118,7 @@ struct SecurityToast { try { display.on('change', (data: number) => { - Log.info(`Listening enabled. Data: ${JSON.stringify(data)}`); + Log.info(`Listening change. Data: ${JSON.stringify(data)}`); let rotation: number = display.getDefaultDisplaySync().orientation; let densityDPI = display.getDefaultDisplaySync().densityDPI; if (rotation !== this.rotationInit) { -- Gitee