diff --git a/apps/desktop/src/main/window.main.ts b/apps/desktop/src/main/window.main.ts index 5b58172ac1..b1d88a821f 100644 --- a/apps/desktop/src/main/window.main.ts +++ b/apps/desktop/src/main/window.main.ts @@ -5,6 +5,7 @@ import { app, BrowserWindow, screen } from "electron"; import { LogService } from "@bitwarden/common/abstractions/log.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; +import { WindowState } from "@bitwarden/common/models/domain/window-state"; import { cleanUserAgent, isDev, isMacAppStore, isSnapStore } from "../utils"; @@ -13,9 +14,10 @@ const WindowEventHandlingDelay = 100; export class WindowMain { win: BrowserWindow; isQuitting = false; + isClosing = false; private windowStateChangeTimer: NodeJS.Timer; - private windowStates: { [key: string]: any } = {}; + private windowStates: { [key: string]: WindowState } = {}; private enableAlwaysOnTop = false; constructor( @@ -128,6 +130,10 @@ export class WindowMain { }, }); + this.win.webContents.on("dom-ready", () => { + this.win.webContents.zoomFactor = this.windowStates[mainWindowSizeKey].zoomFactor ?? 1.0; + }); + if (this.windowStates[mainWindowSizeKey].isMaximized) { this.win.maximize(); } @@ -154,6 +160,7 @@ export class WindowMain { // Emitted when the window is closed. this.win.on("closed", async () => { + this.isClosing = false; await this.updateWindowState(mainWindowSizeKey, this.win); // Dereference the window object, usually you would store window @@ -163,6 +170,7 @@ export class WindowMain { }); this.win.on("close", async () => { + this.isClosing = true; await this.updateWindowState(mainWindowSizeKey, this.win); }); @@ -217,7 +225,7 @@ export class WindowMain { if (this.windowStates[configKey] == null) { this.windowStates[configKey] = await this.stateService.getWindow(); if (this.windowStates[configKey] == null) { - this.windowStates[configKey] = {}; + this.windowStates[configKey] = {}; } } @@ -231,6 +239,10 @@ export class WindowMain { this.windowStates[configKey].height = bounds.height; } + if (this.isClosing) { + this.windowStates[configKey].zoomFactor = win.webContents.zoomFactor; + } + await this.stateService.setWindow(this.windowStates[configKey]); } catch (e) { this.logService.error(e); diff --git a/libs/common/src/models/domain/window-state.ts b/libs/common/src/models/domain/window-state.ts index cb260d8b08..99a1e53658 100644 --- a/libs/common/src/models/domain/window-state.ts +++ b/libs/common/src/models/domain/window-state.ts @@ -7,4 +7,5 @@ export class WindowState { displayBounds: any; x?: number; y?: number; + zoomFactor?: number; }