diff --git a/common/src/abstractions/state.service.ts b/common/src/abstractions/state.service.ts index 693feb7eb3..bf00d744ff 100644 --- a/common/src/abstractions/state.service.ts +++ b/common/src/abstractions/state.service.ts @@ -19,6 +19,7 @@ import { GeneratedPasswordHistory } from "../models/domain/generatedPasswordHist import { Policy } from "../models/domain/policy"; import { StorageOptions } from "../models/domain/storageOptions"; import { SymmetricCryptoKey } from "../models/domain/symmetricCryptoKey"; +import { WindowState } from "../models/domain/windowState"; import { CipherView } from "../models/view/cipherView"; import { CollectionView } from "../models/view/collectionView"; @@ -299,6 +300,6 @@ export abstract class StateService { setVaultTimeoutAction: (value: string, options?: StorageOptions) => Promise; getStateVersion: () => Promise; setStateVersion: (value: number) => Promise; - getWindow: () => Promise>; - setWindow: (value: Map) => Promise; + getWindow: () => Promise; + setWindow: (value: WindowState) => Promise; } diff --git a/common/src/models/domain/globalState.ts b/common/src/models/domain/globalState.ts index 90d53d7f90..4fb143351d 100644 --- a/common/src/models/domain/globalState.ts +++ b/common/src/models/domain/globalState.ts @@ -1,5 +1,6 @@ import { StateVersion } from "../../enums/stateVersion"; import { EnvironmentUrls } from "./environmentUrls"; +import { WindowState } from "./windowState"; export class GlobalState { enableAlwaysOnTop?: boolean; @@ -11,7 +12,7 @@ export class GlobalState { ssoState?: string; rememberedEmail?: string; theme?: string = "light"; - window?: Map = new Map(); + window?: WindowState = new WindowState(); twoFactorToken?: string; disableFavicon?: boolean; biometricAwaitingAcceptance?: boolean; diff --git a/common/src/models/domain/windowState.ts b/common/src/models/domain/windowState.ts new file mode 100644 index 0000000000..cb260d8b08 --- /dev/null +++ b/common/src/models/domain/windowState.ts @@ -0,0 +1,10 @@ +export class WindowState { + width?: number; + height?: number; + isMaximized?: boolean; + // TODO: displayBounds is an Electron.Rectangle. + // We need to establish some kind of client-specific global state, similiar to the way we already extend a base Account. + displayBounds: any; + x?: number; + y?: number; +} diff --git a/common/src/services/state.service.ts b/common/src/services/state.service.ts index a0178fd3b5..0bacc5e8a6 100644 --- a/common/src/services/state.service.ts +++ b/common/src/services/state.service.ts @@ -36,6 +36,7 @@ import { BehaviorSubject } from "rxjs"; import { StateMigrationService } from "../abstractions/stateMigration.service"; import { EnvironmentUrls } from "../models/domain/environmentUrls"; +import { WindowState } from "../models/domain/windowState"; const keys = { global: "global", @@ -2066,14 +2067,14 @@ export class StateService await this.saveGlobals(globals, await this.defaultOnDiskOptions()); } - async getWindow(): Promise> { + async getWindow(): Promise { const globals = await this.getGlobals(await this.defaultOnDiskOptions()); return globals?.window != null && Object.keys(globals.window).length > 0 ? globals.window - : new Map(); + : new WindowState(); } - async setWindow(value: Map, options?: StorageOptions): Promise { + async setWindow(value: WindowState, options?: StorageOptions): Promise { const globals = await this.getGlobals( this.reconcileOptions(options, await this.defaultOnDiskOptions()) ); diff --git a/electron/src/window.main.ts b/electron/src/window.main.ts index e335586382..2dc1709ef9 100644 --- a/electron/src/window.main.ts +++ b/electron/src/window.main.ts @@ -99,7 +99,6 @@ export class WindowMain { async createWindow(): Promise { this.windowStates[mainWindowSizeKey] = await this.getWindowState( - mainWindowSizeKey, this.defaultWidth, this.defaultHeight ); @@ -214,7 +213,7 @@ export class WindowMain { const bounds = win.getBounds(); if (this.windowStates[configKey] == null) { - this.windowStates[configKey] = (await this.stateService.getWindow()).get(configKey); + this.windowStates[configKey] = await this.stateService.getWindow(); if (this.windowStates[configKey] == null) { this.windowStates[configKey] = {}; } @@ -230,25 +229,20 @@ export class WindowMain { this.windowStates[configKey].height = bounds.height; } - const cachedWindow = (await this.stateService.getWindow()) ?? new Map(); - cachedWindow.set(configKey, this.windowStates[configKey]); - await this.stateService.setWindow(cachedWindow); + await this.stateService.setWindow(this.windowStates[configKey]); } catch (e) { this.logService.error(e); } } - private async getWindowState(configKey: string, defaultWidth: number, defaultHeight: number) { - const windowState = (await this.stateService.getWindow()) ?? new Map(); - let state = windowState.has(configKey) ? windowState.get(configKey) : null; + private async getWindowState(defaultWidth: number, defaultHeight: number) { + const state = await this.stateService.getWindow(); const isValid = state != null && (this.stateHasBounds(state) || state.isMaximized); let displayBounds: Electron.Rectangle = null; if (!isValid) { - state = { - width: defaultWidth, - height: defaultHeight, - }; + state.width = defaultWidth; + state.height = defaultHeight; displayBounds = screen.getPrimaryDisplay().bounds; } else if (this.stateHasBounds(state) && state.displayBounds) {