From a8d72fa665df1077d299dfaf87faceedda2a0e84 Mon Sep 17 00:00:00 2001 From: MrGarlic1 <61215937+MrGarlic1@users.noreply.github.com> Date: Fri, 10 May 2024 15:04:16 -0400 Subject: [PATCH] fix: do not re-position on screen that was disconnected (#598) Co-authored-by: MrGarlic --- src/main/mainWindow.ts | 6 +++++- src/shared/settings.d.ts | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 7e0afde..3ee1fd0 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -12,6 +12,7 @@ import { Menu, MenuItemConstructorOptions, nativeTheme, + screen, Tray } from "electron"; import { rm } from "fs/promises"; @@ -269,7 +270,9 @@ function getWindowBoundsOptions(): BrowserWindowConstructorOptions { height: height ?? DEFAULT_HEIGHT } as BrowserWindowConstructorOptions; - if (x != null && y != null) { + const storedDisplay = screen.getAllDisplays().find(display => display.id === State.store.displayid); + + if (x != null && y != null && storedDisplay) { options.x = x; options.y = y; } @@ -317,6 +320,7 @@ function initWindowBoundsListeners(win: BrowserWindow) { const saveBounds = () => { State.store.windowBounds = win.getBounds(); + State.store.displayid = screen.getDisplayMatching(State.store.windowBounds).id; }; win.on("resize", saveBounds); diff --git a/src/shared/settings.d.ts b/src/shared/settings.d.ts index 7f6e74a..4678751 100644 --- a/src/shared/settings.d.ts +++ b/src/shared/settings.d.ts @@ -36,6 +36,7 @@ export interface State { maximized?: boolean; minimized?: boolean; windowBounds?: Rectangle; + displayid: int; skippedUpdate?: string; firstLaunch?: boolean;