1/** 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { ILayoutConfig } from './ILayoutConfig'; 17import { CommonConstants } from '../constants/CommonConstants'; 18import defaultLayoutConfig from '../configs/DefaultLayoutConfig'; 19 20/** 21 * Desktop Workspace Layout Mode Configuration 22 */ 23export class PageDesktopModeConfig extends ILayoutConfig { 24 /** 25 * Workspace layout mode configuration index 26 */ 27 static DESKTOP_MODE_CONFIG = 'DesktopModeConfig'; 28 29 private static readonly APP_PAGE_START_CONFIG = 'AppStartPageType'; 30 31 private static readonly GRID_CONFIG = 'GridConfig'; 32 33 private mAppStartPageType: string = defaultLayoutConfig.defaultAppPageStartConfig; 34 35 private mGridConfig: number = defaultLayoutConfig.defaultGridConfig; 36 37 private mDeviceType: string = defaultLayoutConfig.defaultDeviceType; 38 39 protected constructor() { 40 super(); 41 } 42 43 /** 44 * Get an instance of the workspace layout mode configuration 45 */ 46 static getInstance(): PageDesktopModeConfig { 47 if (globalThis.PageDesktopModeConfigInstance == null) { 48 globalThis.PageDesktopModeConfigInstance = new PageDesktopModeConfig(); 49 globalThis.PageDesktopModeConfigInstance.initConfig(); 50 } 51 return globalThis.PageDesktopModeConfigInstance; 52 } 53 54 initConfig(): void { 55 const config = this.loadPersistConfig(); 56 this.mAppStartPageType = config.appStartPageType; 57 this.mGridConfig = config.gridConfig; 58 this.mDeviceType = config.deviceType; 59 } 60 61 getConfigLevel(): string { 62 return CommonConstants.LAYOUT_CONFIG_LEVEL_COMMON; 63 } 64 65 getConfigType(): number { 66 return CommonConstants.LAYOUT_CONFIG_TYPE_MODE; 67 } 68 69 getConfigName(): string { 70 return PageDesktopModeConfig.DESKTOP_MODE_CONFIG; 71 } 72 73 protected getPersistConfigJson(): string { 74 const persistConfig = { 75 appStartPageType: this.mAppStartPageType, 76 gridConfig: this.mGridConfig, 77 deviceType: this.mDeviceType 78 }; 79 return JSON.stringify(persistConfig); 80 } 81 82 /** 83 * Update default desktop mode 84 * 85 * @param startPageType:Default desktop mode 86 */ 87 updateAppStartPageType(startPageType: string): void { 88 this.mAppStartPageType = startPageType; 89 globalThis.RdbStoreManagerInstance.updateSettings('app_start_page_type', startPageType); 90 } 91 92 /** 93 * Get default desktop mode 94 * 95 * @return startPageType:Default desktop mode 96 */ 97 getAppStartPageType(): string { 98 return this.mAppStartPageType; 99 } 100 101 /** 102 * Update grid layout mode 103 * 104 * @param gridConfig 105 */ 106 updateGridConfig(gridConfig: number): void { 107 this.mGridConfig = gridConfig; 108 globalThis.RdbStoreManagerInstance.updateSettings('grid_config', gridConfig); 109 } 110 111 /** 112 * Get grid layout mode 113 * 114 * @return gridConfig:grid layout mode 115 */ 116 getGridConfig(): number { 117 return this.mGridConfig; 118 } 119 120 /** 121 * Update layout device type 122 * 123 * @param deviceType 124 */ 125 updateDeviceType(deviceType: string): void { 126 this.mDeviceType = deviceType; 127 globalThis.RdbStoreManagerInstance.updateSettings('device_type', deviceType); 128 } 129 130 /** 131 * Get layout device type 132 * 133 * @return deviceType 134 */ 135 getDeviceType(): string { 136 return this.mDeviceType; 137 } 138} 139