From 0a49f1ef561a4b71acb7b1b0959ed89502618b15 Mon Sep 17 00:00:00 2001 From: lon9 <815882449@qq.com> Date: Fri, 27 Dec 2024 11:29:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AA=97=E5=8F=A3=E5=B7=A5=E5=85=B7=E7=B1=BB?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BC=82=E5=B8=B8=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/src/main/ets/utils/WindowUtil.ets | 72 ++++++++++++++++--- 1 file changed, 61 insertions(+), 11 deletions(-) diff --git a/commons/base/src/main/ets/utils/WindowUtil.ets b/commons/base/src/main/ets/utils/WindowUtil.ets index 98f46dd..2547b96 100644 --- a/commons/base/src/main/ets/utils/WindowUtil.ets +++ b/commons/base/src/main/ets/utils/WindowUtil.ets @@ -13,10 +13,10 @@ * limitations under the License. */ -import { deviceInfo } from '@kit.BasicServicesKit'; +import { BusinessError, deviceInfo } from '@kit.BasicServicesKit'; import { display, window } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; import { CommonConstants } from '../constants/CommonConstants'; -import Logger from './Logger'; @Observed export class WindowUtil { @@ -27,7 +27,7 @@ export class WindowUtil { if (!AppStorage.get(CommonConstants.WINDOW_UTIL)) { AppStorage.setOrCreate(CommonConstants.WINDOW_UTIL, new WindowUtil()); } else { - Logger.info(`AppStorage does not have windowUtil`); + hilog.info(0x0000, 'testTag', '%{public}s', `AppStorage does not have windowUtil.`); } return AppStorage.get(CommonConstants.WINDOW_UTIL); } @@ -37,7 +37,8 @@ export class WindowUtil { this.windowStage.getMainWindow((err, windowClass: window.Window) => { this.mainWindowClass = windowClass; if (err.code) { - Logger.error(`Failed to obtain the main window. Code:${err.code}, message:${err.message}`); + hilog.error(0x0000, 'testTag', `Failed to obtain the main window. Code:${err.code}, message:${err.message}`, + JSON.stringify(err) ?? ''); return; } }); @@ -45,32 +46,76 @@ export class WindowUtil { setMainWindowOrientation(orientation: window.Orientation): void { // Setting orientation. - this.mainWindowClass!.setPreferredOrientation(orientation); + this.mainWindowClass!.setPreferredOrientation(orientation) + .then(() => { + hilog.info(0x0000, 'testTag', '%{public}s', `Succeed in setting the orientation.`); + }) + .catch((err: BusinessError) => { + hilog.error(0x0000, 'testTag', `Failed to set the orientation. Code: ${err.code}, message: ${err.message}`, + JSON.stringify(err) ?? ''); + }); } disableWindowSystemBar(): void { // Set the status bar and navigation bar to be invisible in full-screen mode. - this.mainWindowClass!.setWindowSystemBarEnable([]); + this.mainWindowClass!.setWindowSystemBarEnable([]) + .then(() => { + hilog.info(0x0000, 'testTag', '%{public}s', `Succeed in setting the window system bar disable.`); + }) + .catch((err: BusinessError) => { + hilog.error(0x0000, 'testTag', + `Failed to set the window system bar disable. Code: ${err.code}, message: ${err.message}`, + JSON.stringify(err) ?? ''); + }); } enableWindowSystemBar(): void { - this.mainWindowClass!.setWindowSystemBarEnable(['status', 'navigation']); + this.mainWindowClass!.setWindowSystemBarEnable(['status', 'navigation']) + .then(() => { + hilog.info(0x0000, 'testTag', '%{public}s', `Succeed in setting the window system bar enable.`); + }) + .catch((err: BusinessError) => { + hilog.error(0x0000, 'testTag', `Failed to set the orientation. Code: ${err.code}, message: ${err.message}`, + JSON.stringify(err) ?? ''); + }); } setFullScreen(): void { // Set full-screen display. - this.mainWindowClass!.setWindowLayoutFullScreen(true); + this.mainWindowClass!.setWindowLayoutFullScreen(true) + .then(() => { + hilog.info(0x0000, 'testTag', '%{public}s', `Succeed in setting the window layout full screen.`); + }) + .catch((err: BusinessError) => { + hilog.error(0x0000, 'testTag', + `Failed to set the window layout full screen. Code: ${err.code}, message: ${err.message}`, + JSON.stringify(err) ?? ''); + }); } maximize(): void { if (this.mainWindowClass!.getWindowStatus() === window.WindowStatusType.FLOATING) { - this.mainWindowClass!.maximize(); + this.mainWindowClass!.maximize() + .then(() => { + hilog.info(0x0000, 'testTag', '%{public}s', `Succeed in maximizing the window.`); + }) + .catch((err: BusinessError) => { + hilog.error(0x0000, 'testTag', `Failed to maximize the window. Code: ${err.code}, message: ${err.message}`, + JSON.stringify(err) ?? ''); + }); } } recover(): void { if (this.mainWindowClass!.getWindowStatus() === window.WindowStatusType.FULL_SCREEN) { - this.mainWindowClass!.recover(); + this.mainWindowClass!.recover() + .then(() => { + hilog.info(0x0000, 'testTag', '%{public}s', `Succeed in rovering the window.`); + }) + .catch((err: BusinessError) => { + hilog.error(0x0000, 'testTag', `Failed to rover the window. Code: ${err.code}, message: ${err.message}`, + JSON.stringify(err) ?? ''); + }); } } @@ -79,7 +124,12 @@ export class WindowUtil { } offWindowSizeChange(): void { - this.mainWindowClass!.off('windowSizeChange'); + try { + this.mainWindowClass!.off('windowSizeChange'); + } catch (err) { + hilog.error(0x0000, 'testTag', `Failed to off window size change. Code: ${err.code}, message: ${err.message}`, + JSON.stringify(err) ?? ''); + } } updateWidthBp(): void { -- Gitee