From f75c010ecba775cf800c4ac4b79d3bc391098f6d Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Tue, 14 Feb 2023 11:40:47 +0500 Subject: [PATCH] desktop: save window state eagerly as soon as its updated --- apps/web/desktop/config/window-state.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/web/desktop/config/window-state.ts b/apps/web/desktop/config/window-state.ts index eb07ce743..0d9ce9f63 100644 --- a/apps/web/desktop/config/window-state.ts +++ b/apps/web/desktop/config/window-state.ts @@ -43,7 +43,7 @@ export class WindowState { private readonly config: WindowStateOptions; private state: SerializableWindowState; private windowRef: BrowserWindow | undefined; - private readonly eventHandlingDelay = 100; + private readonly eventHandlingDelay = 1000; private stateChangeTimer: NodeJS.Timeout | undefined; constructor(options?: Partial) { @@ -176,7 +176,7 @@ export class WindowState { // Handles both 'resize' and 'move' if (this.stateChangeTimer) clearTimeout(this.stateChangeTimer); this.stateChangeTimer = setTimeout( - () => this.updateState(), + () => this.saveState(this.windowRef), this.eventHandlingDelay ); }; @@ -199,8 +199,8 @@ export class WindowState { if (this.config.fullScreen && this.state.isFullScreen) { win.setFullScreen(true); } - win.on("resize", this.stateChangeHandler); - win.on("move", this.stateChangeHandler); + win.on("resized", this.stateChangeHandler); + win.on("moved", this.stateChangeHandler); win.on("close", this.closeHandler); win.on("closed", this.closedHandler); this.windowRef = win; @@ -208,8 +208,8 @@ export class WindowState { unmanage() { if (this.windowRef) { - this.windowRef.removeListener("resize", this.stateChangeHandler); - this.windowRef.removeListener("move", this.stateChangeHandler); + this.windowRef.removeListener("resized", this.stateChangeHandler); + this.windowRef.removeListener("moved", this.stateChangeHandler); if (this.stateChangeTimer) clearTimeout(this.stateChangeTimer); this.windowRef.removeListener("close", this.closeHandler); this.windowRef.removeListener("closed", this.closedHandler);