16e80583aSopenharmony_ci/** 26e80583aSopenharmony_ci * Copyright (c) 2022-2022 Huawei Device Co., Ltd. 36e80583aSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 46e80583aSopenharmony_ci * you may not use this file except in compliance with the License. 56e80583aSopenharmony_ci * You may obtain a copy of the License at 66e80583aSopenharmony_ci * 76e80583aSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 86e80583aSopenharmony_ci * 96e80583aSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 106e80583aSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 116e80583aSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 126e80583aSopenharmony_ci * See the License for the specific language governing permissions and 136e80583aSopenharmony_ci * limitations under the License. 146e80583aSopenharmony_ci */ 156e80583aSopenharmony_ci 166e80583aSopenharmony_ciimport { BaseCloseAppHandler } from '../base/BaseCloseAppHandler'; 176e80583aSopenharmony_ciimport { CheckEmptyUtils } from '../utils/CheckEmptyUtils'; 186e80583aSopenharmony_ciimport { Log } from '../utils/Log'; 196e80583aSopenharmony_ci 206e80583aSopenharmony_ciconst TAG = 'CloseAppManager'; 216e80583aSopenharmony_ci 226e80583aSopenharmony_ci/** 236e80583aSopenharmony_ci * close app manager 246e80583aSopenharmony_ci */ 256e80583aSopenharmony_ciexport class CloseAppManager { 266e80583aSopenharmony_ci private mBaseCloseAppHandlerList: Array<BaseCloseAppHandler> = new Array<BaseCloseAppHandler>(); 276e80583aSopenharmony_ci private mPagedesktopCloseItemInfo: any; 286e80583aSopenharmony_ci private mPagedesktopClosePosition: { 296e80583aSopenharmony_ci appIconSize: number, 306e80583aSopenharmony_ci appIconHeight: number, 316e80583aSopenharmony_ci appIconPositionX: number, 326e80583aSopenharmony_ci appIconPositionY: number 336e80583aSopenharmony_ci } = { appIconSize: 0, 346e80583aSopenharmony_ci appIconHeight: 0, 356e80583aSopenharmony_ci appIconPositionX: 0, 366e80583aSopenharmony_ci appIconPositionY: 0 }; 376e80583aSopenharmony_ci private mSmartdockCloseItemInfo: any; 386e80583aSopenharmony_ci private mSmartdockClosePosition: { 396e80583aSopenharmony_ci appIconSize: number, 406e80583aSopenharmony_ci appIconHeight: number, 416e80583aSopenharmony_ci appIconPositionX: number, 426e80583aSopenharmony_ci appIconPositionY: number 436e80583aSopenharmony_ci } = { appIconSize: 0, 446e80583aSopenharmony_ci appIconHeight: 0, 456e80583aSopenharmony_ci appIconPositionX: 0, 466e80583aSopenharmony_ci appIconPositionY: 0 } 476e80583aSopenharmony_ci 486e80583aSopenharmony_ci constructor() { 496e80583aSopenharmony_ci } 506e80583aSopenharmony_ci 516e80583aSopenharmony_ci static getInstance(): CloseAppManager { 526e80583aSopenharmony_ci if (globalThis.CloseAppManager == null) { 536e80583aSopenharmony_ci globalThis.CloseAppManager = new CloseAppManager(); 546e80583aSopenharmony_ci } 556e80583aSopenharmony_ci return globalThis.CloseAppManager; 566e80583aSopenharmony_ci } 576e80583aSopenharmony_ci 586e80583aSopenharmony_ci /** 596e80583aSopenharmony_ci * register baseCloseAppHandler to manager 606e80583aSopenharmony_ci * 616e80583aSopenharmony_ci * @param baseCloseAppHandler the instance of close app handler 626e80583aSopenharmony_ci */ 636e80583aSopenharmony_ci public registerCloseAppHandler(baseCloseAppHandler: BaseCloseAppHandler): void { 646e80583aSopenharmony_ci if (CheckEmptyUtils.isEmpty(baseCloseAppHandler)) { 656e80583aSopenharmony_ci Log.showError(TAG, 'registerCloseAppHandler with invalid baseCloseAppHandler') 666e80583aSopenharmony_ci return; 676e80583aSopenharmony_ci } 686e80583aSopenharmony_ci 696e80583aSopenharmony_ci this.mBaseCloseAppHandlerList.push(baseCloseAppHandler); 706e80583aSopenharmony_ci Log.showInfo(TAG, `registerCloseAppHandler mBaseCloseAppHandlerList is ${this.mBaseCloseAppHandlerList.length}} `) 716e80583aSopenharmony_ci } 726e80583aSopenharmony_ci 736e80583aSopenharmony_ci /** 746e80583aSopenharmony_ci * unregister baseCloseAppHandler to manager 756e80583aSopenharmony_ci * 766e80583aSopenharmony_ci * @param baseCloseAppHandler the instance of close app handler 776e80583aSopenharmony_ci */ 786e80583aSopenharmony_ci public unregisterCloseAppHandler(baseCloseAppHandler: BaseCloseAppHandler): void { 796e80583aSopenharmony_ci if (CheckEmptyUtils.isEmpty(baseCloseAppHandler)) { 806e80583aSopenharmony_ci Log.showError(TAG, 'unregisterCloseAppHandler with invalid baseCloseAppHandler') 816e80583aSopenharmony_ci return; 826e80583aSopenharmony_ci } 836e80583aSopenharmony_ci 846e80583aSopenharmony_ci let index: number = 0; 856e80583aSopenharmony_ci for (var i = 0; i < this.mBaseCloseAppHandlerList.length; i++) { 866e80583aSopenharmony_ci if (this.mBaseCloseAppHandlerList[i] === baseCloseAppHandler) { 876e80583aSopenharmony_ci index = i; 886e80583aSopenharmony_ci break; 896e80583aSopenharmony_ci } 906e80583aSopenharmony_ci } 916e80583aSopenharmony_ci 926e80583aSopenharmony_ci this.mBaseCloseAppHandlerList.splice(index, 1); 936e80583aSopenharmony_ci Log.showInfo(TAG, `unregisterCloseAppHandler mBaseCloseAppHandlerList is ${this.mBaseCloseAppHandlerList.length}`) 946e80583aSopenharmony_ci } 956e80583aSopenharmony_ci 966e80583aSopenharmony_ci /** 976e80583aSopenharmony_ci * get app icon info 986e80583aSopenharmony_ci * 996e80583aSopenharmony_ci * @param windowTarget windowTarget close window target 1006e80583aSopenharmony_ci */ 1016e80583aSopenharmony_ci public getAppIconInfo(windowTarget): void { 1026e80583aSopenharmony_ci if (CheckEmptyUtils.isEmptyArr(this.mBaseCloseAppHandlerList)) { 1036e80583aSopenharmony_ci Log.showError(TAG, 'getAppIconInfo with invalid mBaseCloseAppHandlerList'); 1046e80583aSopenharmony_ci return; 1056e80583aSopenharmony_ci } 1066e80583aSopenharmony_ci 1076e80583aSopenharmony_ci for (var i = 0; i < this.mBaseCloseAppHandlerList.length; i++) { 1086e80583aSopenharmony_ci this.mBaseCloseAppHandlerList[i].getAppIconInfo(windowTarget); 1096e80583aSopenharmony_ci } 1106e80583aSopenharmony_ci } 1116e80583aSopenharmony_ci 1126e80583aSopenharmony_ci /** 1136e80583aSopenharmony_ci * get app icon info 1146e80583aSopenharmony_ci * 1156e80583aSopenharmony_ci * @param windowTarget windowTarget close window target 1166e80583aSopenharmony_ci */ 1176e80583aSopenharmony_ci public getAppInfo(windowTarget): any { 1186e80583aSopenharmony_ci if (CheckEmptyUtils.isEmptyArr(this.mBaseCloseAppHandlerList)) { 1196e80583aSopenharmony_ci Log.showError(TAG, 'getAppIconInfo with invalid mBaseCloseAppHandlerList'); 1206e80583aSopenharmony_ci return {}; 1216e80583aSopenharmony_ci } 1226e80583aSopenharmony_ci 1236e80583aSopenharmony_ci for (var i = 0; i < this.mBaseCloseAppHandlerList.length; i++) { 1246e80583aSopenharmony_ci this.mBaseCloseAppHandlerList[i].getAppIconInfo(windowTarget); 1256e80583aSopenharmony_ci } 1266e80583aSopenharmony_ci 1276e80583aSopenharmony_ci return {iconInfo: this.getAppCloseIconInfo(), appItemInfo: this.getAppCloseItemInfo()} 1286e80583aSopenharmony_ci } 1296e80583aSopenharmony_ci 1306e80583aSopenharmony_ci public addPagedesktopClosePosition(pagedesktopCloseIconInfo: any, pagedesktopCloseItemInfo?: any) { 1316e80583aSopenharmony_ci Log.showDebug(TAG, `addPagedesktopClosePosition pagedesktopCloasIconInfo is ${JSON.stringify(pagedesktopCloseIconInfo)}`) 1326e80583aSopenharmony_ci this.mPagedesktopClosePosition = pagedesktopCloseIconInfo; 1336e80583aSopenharmony_ci this.mPagedesktopCloseItemInfo = pagedesktopCloseItemInfo; 1346e80583aSopenharmony_ci } 1356e80583aSopenharmony_ci 1366e80583aSopenharmony_ci public addSmartDockClosePosition(smartdockCloseIconInfo: any, smartdockCloseItemInfo: any) { 1376e80583aSopenharmony_ci Log.showDebug(TAG, `addSmartDockClosePosition smartdockCloasIconInfo is ${JSON.stringify(smartdockCloseIconInfo)}`) 1386e80583aSopenharmony_ci this.mSmartdockClosePosition = smartdockCloseIconInfo; 1396e80583aSopenharmony_ci this.mSmartdockCloseItemInfo = smartdockCloseItemInfo; 1406e80583aSopenharmony_ci } 1416e80583aSopenharmony_ci 1426e80583aSopenharmony_ci public getAppCloseIconInfo(): any { 1436e80583aSopenharmony_ci if (CheckEmptyUtils.isEmpty(this.mPagedesktopClosePosition)) { 1446e80583aSopenharmony_ci Log.showDebug(TAG, `getAppCloseIconInfo return mSmartdockClosePosition is ${JSON.stringify(this.mSmartdockClosePosition)}`) 1456e80583aSopenharmony_ci return this.mSmartdockClosePosition; 1466e80583aSopenharmony_ci } else { 1476e80583aSopenharmony_ci Log.showDebug(TAG, `getAppCloseIconInfo return mPagedesktopClosePosition is ${JSON.stringify(this.mPagedesktopClosePosition)}`) 1486e80583aSopenharmony_ci return this.mPagedesktopClosePosition; 1496e80583aSopenharmony_ci } 1506e80583aSopenharmony_ci } 1516e80583aSopenharmony_ci 1526e80583aSopenharmony_ci public getAppCloseItemInfo(): any { 1536e80583aSopenharmony_ci if (CheckEmptyUtils.isEmpty(this.mPagedesktopClosePosition)) { 1546e80583aSopenharmony_ci Log.showDebug(TAG, `getAppCloseIconInfo return mSmartdockClosePosition is ${JSON.stringify(this.mSmartdockClosePosition)}`) 1556e80583aSopenharmony_ci return this.mSmartdockCloseItemInfo; 1566e80583aSopenharmony_ci } else { 1576e80583aSopenharmony_ci Log.showDebug(TAG, `getAppCloseIconInfo return mPagedesktopClosePosition is ${JSON.stringify(this.mPagedesktopClosePosition)}`) 1586e80583aSopenharmony_ci return this.mPagedesktopCloseItemInfo; 1596e80583aSopenharmony_ci } 1606e80583aSopenharmony_ci } 1616e80583aSopenharmony_ci} 162