16e80583aSopenharmony_ci/** 26e80583aSopenharmony_ci * Copyright (c) 2021-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 { Log } from '../utils/Log'; 176e80583aSopenharmony_ciimport { ILayoutConfig } from './ILayoutConfig'; 186e80583aSopenharmony_ciimport { CommonConstants } from '../constants/CommonConstants'; 196e80583aSopenharmony_ci 206e80583aSopenharmony_ciconst TAG = 'PageDesktopAppModeConfig'; 216e80583aSopenharmony_ci 226e80583aSopenharmony_ci/** 236e80583aSopenharmony_ci * Desktop Workspace App Configuration 246e80583aSopenharmony_ci */ 256e80583aSopenharmony_ciexport class PageDesktopAppModeConfig extends ILayoutConfig { 266e80583aSopenharmony_ci /** 276e80583aSopenharmony_ci * Workspace Feature Layout Configuration Index 286e80583aSopenharmony_ci */ 296e80583aSopenharmony_ci static DESKTOP_APPLICATION_INFO = 'DesktopApplicationInfo'; 306e80583aSopenharmony_ci 316e80583aSopenharmony_ci private static readonly DEFAULT_LAYOUT_INFO: any = []; 326e80583aSopenharmony_ci 336e80583aSopenharmony_ci private mAppListInfo: any = PageDesktopAppModeConfig.DEFAULT_LAYOUT_INFO; 346e80583aSopenharmony_ci 356e80583aSopenharmony_ci protected constructor() { 366e80583aSopenharmony_ci super(); 376e80583aSopenharmony_ci } 386e80583aSopenharmony_ci 396e80583aSopenharmony_ci /** 406e80583aSopenharmony_ci * Get an instance of the workspace function layout configuration 416e80583aSopenharmony_ci */ 426e80583aSopenharmony_ci static getInstance(): PageDesktopAppModeConfig { 436e80583aSopenharmony_ci if (globalThis.PageDesktopAppModeConfig == null) { 446e80583aSopenharmony_ci globalThis.PageDesktopAppModeConfig = new PageDesktopAppModeConfig(); 456e80583aSopenharmony_ci globalThis.PageDesktopAppModeConfig.initConfig(); 466e80583aSopenharmony_ci } 476e80583aSopenharmony_ci return globalThis.PageDesktopAppModeConfig; 486e80583aSopenharmony_ci } 496e80583aSopenharmony_ci 506e80583aSopenharmony_ci initConfig(): void { 516e80583aSopenharmony_ci this.loadPersistConfig(); 526e80583aSopenharmony_ci } 536e80583aSopenharmony_ci 546e80583aSopenharmony_ci getConfigLevel(): string { 556e80583aSopenharmony_ci return CommonConstants.LAYOUT_CONFIG_LEVEL_COMMON; 566e80583aSopenharmony_ci } 576e80583aSopenharmony_ci 586e80583aSopenharmony_ci getConfigType(): number { 596e80583aSopenharmony_ci return CommonConstants.LAYOUT_CONFIG_TYPE_MODE; 606e80583aSopenharmony_ci } 616e80583aSopenharmony_ci 626e80583aSopenharmony_ci getConfigName(): string { 636e80583aSopenharmony_ci return PageDesktopAppModeConfig.DESKTOP_APPLICATION_INFO; 646e80583aSopenharmony_ci } 656e80583aSopenharmony_ci 666e80583aSopenharmony_ci protected getPersistConfigJson(): string { 676e80583aSopenharmony_ci return JSON.stringify(this.mAppListInfo); 686e80583aSopenharmony_ci } 696e80583aSopenharmony_ci 706e80583aSopenharmony_ci /** 716e80583aSopenharmony_ci * update appList in desktop 726e80583aSopenharmony_ci * 736e80583aSopenharmony_ci * @params appListInfo 746e80583aSopenharmony_ci */ 756e80583aSopenharmony_ci updateAppListInfo(appListInfo: object): void { 766e80583aSopenharmony_ci this.mAppListInfo = appListInfo; 776e80583aSopenharmony_ci super.persistConfig(); 786e80583aSopenharmony_ci globalThis.RdbStoreManagerInstance.insertDesktopApplication(appListInfo).then((result) => { 796e80583aSopenharmony_ci Log.showDebug(TAG, 'updateAppListInfo success.'); 806e80583aSopenharmony_ci }).catch((err) => { 816e80583aSopenharmony_ci Log.showError(TAG, `updateAppListInfo error: ${err.toString()}`); 826e80583aSopenharmony_ci }); 836e80583aSopenharmony_ci } 846e80583aSopenharmony_ci 856e80583aSopenharmony_ci /** 866e80583aSopenharmony_ci * Get workspace shortcuts 876e80583aSopenharmony_ci * 886e80583aSopenharmony_ci * @return Workspace shortcuts 896e80583aSopenharmony_ci */ 906e80583aSopenharmony_ci getAppListInfo(): any { 916e80583aSopenharmony_ci return this.mAppListInfo; 926e80583aSopenharmony_ci } 936e80583aSopenharmony_ci 946e80583aSopenharmony_ci /** 956e80583aSopenharmony_ci * load configuration 966e80583aSopenharmony_ci */ 976e80583aSopenharmony_ci loadPersistConfig(): void { 986e80583aSopenharmony_ci let defaultConfig = super.loadPersistConfig(); 996e80583aSopenharmony_ci globalThis.RdbStoreManagerInstance.queryDesktopApplication() 1006e80583aSopenharmony_ci .then((config) => { 1016e80583aSopenharmony_ci Log.showDebug(TAG, 'loadPersistConfig configFromRdb success.'); 1026e80583aSopenharmony_ci this.mAppListInfo = config; 1036e80583aSopenharmony_ci }).catch((err) => { 1046e80583aSopenharmony_ci Log.showError(TAG, `loadPersistConfig configFromRdb err: ${err.toString()}`); 1056e80583aSopenharmony_ci this.mAppListInfo = defaultConfig; 1066e80583aSopenharmony_ci }); 1076e80583aSopenharmony_ci } 1086e80583aSopenharmony_ci} 109