diff --git a/commons/base/src/main/ets/utils/WindowUtil.ets b/commons/base/src/main/ets/utils/WindowUtil.ets index 98f46dd4f34f93d35c5870fc04626d777163873c..2547b96ff12ab0adf01369e374c87d3fbc06e429 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 {