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 { ILayoutConfig } from './ILayoutConfig'; 176e80583aSopenharmony_ciimport { CommonConstants } from '../constants/CommonConstants'; 186e80583aSopenharmony_ciimport defaultLayoutConfig from '../configs/DefaultLayoutConfig'; 196e80583aSopenharmony_ci 206e80583aSopenharmony_ci/** 216e80583aSopenharmony_ci * Desktop Workspace Layout Mode Configuration 226e80583aSopenharmony_ci */ 236e80583aSopenharmony_ciexport class PageDesktopModeConfig extends ILayoutConfig { 246e80583aSopenharmony_ci /** 256e80583aSopenharmony_ci * Workspace layout mode configuration index 266e80583aSopenharmony_ci */ 276e80583aSopenharmony_ci static DESKTOP_MODE_CONFIG = 'DesktopModeConfig'; 286e80583aSopenharmony_ci 296e80583aSopenharmony_ci private static readonly APP_PAGE_START_CONFIG = 'AppStartPageType'; 306e80583aSopenharmony_ci 316e80583aSopenharmony_ci private static readonly GRID_CONFIG = 'GridConfig'; 326e80583aSopenharmony_ci 336e80583aSopenharmony_ci private mAppStartPageType: string = defaultLayoutConfig.defaultAppPageStartConfig; 346e80583aSopenharmony_ci 356e80583aSopenharmony_ci private mGridConfig: number = defaultLayoutConfig.defaultGridConfig; 366e80583aSopenharmony_ci 376e80583aSopenharmony_ci private mDeviceType: string = defaultLayoutConfig.defaultDeviceType; 386e80583aSopenharmony_ci 396e80583aSopenharmony_ci protected constructor() { 406e80583aSopenharmony_ci super(); 416e80583aSopenharmony_ci } 426e80583aSopenharmony_ci 436e80583aSopenharmony_ci /** 446e80583aSopenharmony_ci * Get an instance of the workspace layout mode configuration 456e80583aSopenharmony_ci */ 466e80583aSopenharmony_ci static getInstance(): PageDesktopModeConfig { 476e80583aSopenharmony_ci if (globalThis.PageDesktopModeConfigInstance == null) { 486e80583aSopenharmony_ci globalThis.PageDesktopModeConfigInstance = new PageDesktopModeConfig(); 496e80583aSopenharmony_ci globalThis.PageDesktopModeConfigInstance.initConfig(); 506e80583aSopenharmony_ci } 516e80583aSopenharmony_ci return globalThis.PageDesktopModeConfigInstance; 526e80583aSopenharmony_ci } 536e80583aSopenharmony_ci 546e80583aSopenharmony_ci initConfig(): void { 556e80583aSopenharmony_ci const config = this.loadPersistConfig(); 566e80583aSopenharmony_ci this.mAppStartPageType = config.appStartPageType; 576e80583aSopenharmony_ci this.mGridConfig = config.gridConfig; 586e80583aSopenharmony_ci this.mDeviceType = config.deviceType; 596e80583aSopenharmony_ci } 606e80583aSopenharmony_ci 616e80583aSopenharmony_ci getConfigLevel(): string { 626e80583aSopenharmony_ci return CommonConstants.LAYOUT_CONFIG_LEVEL_COMMON; 636e80583aSopenharmony_ci } 646e80583aSopenharmony_ci 656e80583aSopenharmony_ci getConfigType(): number { 666e80583aSopenharmony_ci return CommonConstants.LAYOUT_CONFIG_TYPE_MODE; 676e80583aSopenharmony_ci } 686e80583aSopenharmony_ci 696e80583aSopenharmony_ci getConfigName(): string { 706e80583aSopenharmony_ci return PageDesktopModeConfig.DESKTOP_MODE_CONFIG; 716e80583aSopenharmony_ci } 726e80583aSopenharmony_ci 736e80583aSopenharmony_ci protected getPersistConfigJson(): string { 746e80583aSopenharmony_ci const persistConfig = { 756e80583aSopenharmony_ci appStartPageType: this.mAppStartPageType, 766e80583aSopenharmony_ci gridConfig: this.mGridConfig, 776e80583aSopenharmony_ci deviceType: this.mDeviceType 786e80583aSopenharmony_ci }; 796e80583aSopenharmony_ci return JSON.stringify(persistConfig); 806e80583aSopenharmony_ci } 816e80583aSopenharmony_ci 826e80583aSopenharmony_ci /** 836e80583aSopenharmony_ci * Update default desktop mode 846e80583aSopenharmony_ci * 856e80583aSopenharmony_ci * @param startPageType:Default desktop mode 866e80583aSopenharmony_ci */ 876e80583aSopenharmony_ci updateAppStartPageType(startPageType: string): void { 886e80583aSopenharmony_ci this.mAppStartPageType = startPageType; 896e80583aSopenharmony_ci globalThis.RdbStoreManagerInstance.updateSettings('app_start_page_type', startPageType); 906e80583aSopenharmony_ci } 916e80583aSopenharmony_ci 926e80583aSopenharmony_ci /** 936e80583aSopenharmony_ci * Get default desktop mode 946e80583aSopenharmony_ci * 956e80583aSopenharmony_ci * @return startPageType:Default desktop mode 966e80583aSopenharmony_ci */ 976e80583aSopenharmony_ci getAppStartPageType(): string { 986e80583aSopenharmony_ci return this.mAppStartPageType; 996e80583aSopenharmony_ci } 1006e80583aSopenharmony_ci 1016e80583aSopenharmony_ci /** 1026e80583aSopenharmony_ci * Update grid layout mode 1036e80583aSopenharmony_ci * 1046e80583aSopenharmony_ci * @param gridConfig 1056e80583aSopenharmony_ci */ 1066e80583aSopenharmony_ci updateGridConfig(gridConfig: number): void { 1076e80583aSopenharmony_ci this.mGridConfig = gridConfig; 1086e80583aSopenharmony_ci globalThis.RdbStoreManagerInstance.updateSettings('grid_config', gridConfig); 1096e80583aSopenharmony_ci } 1106e80583aSopenharmony_ci 1116e80583aSopenharmony_ci /** 1126e80583aSopenharmony_ci * Get grid layout mode 1136e80583aSopenharmony_ci * 1146e80583aSopenharmony_ci * @return gridConfig:grid layout mode 1156e80583aSopenharmony_ci */ 1166e80583aSopenharmony_ci getGridConfig(): number { 1176e80583aSopenharmony_ci return this.mGridConfig; 1186e80583aSopenharmony_ci } 1196e80583aSopenharmony_ci 1206e80583aSopenharmony_ci /** 1216e80583aSopenharmony_ci * Update layout device type 1226e80583aSopenharmony_ci * 1236e80583aSopenharmony_ci * @param deviceType 1246e80583aSopenharmony_ci */ 1256e80583aSopenharmony_ci updateDeviceType(deviceType: string): void { 1266e80583aSopenharmony_ci this.mDeviceType = deviceType; 1276e80583aSopenharmony_ci globalThis.RdbStoreManagerInstance.updateSettings('device_type', deviceType); 1286e80583aSopenharmony_ci } 1296e80583aSopenharmony_ci 1306e80583aSopenharmony_ci /** 1316e80583aSopenharmony_ci * Get layout device type 1326e80583aSopenharmony_ci * 1336e80583aSopenharmony_ci * @return deviceType 1346e80583aSopenharmony_ci */ 1356e80583aSopenharmony_ci getDeviceType(): string { 1366e80583aSopenharmony_ci return this.mDeviceType; 1376e80583aSopenharmony_ci } 1386e80583aSopenharmony_ci} 139