add display to state, add display exists check

This commit is contained in:
MrGarlic 2024-05-10 13:59:44 -04:00
parent 69f14ee611
commit 7dcf6a153c
2 changed files with 5 additions and 2 deletions

View file

@ -12,6 +12,7 @@ import {
Menu, Menu,
MenuItemConstructorOptions, MenuItemConstructorOptions,
nativeTheme, nativeTheme,
screen,
Tray Tray
} from "electron"; } from "electron";
import { rm } from "fs/promises"; import { rm } from "fs/promises";
@ -269,7 +270,7 @@ function getWindowBoundsOptions(): BrowserWindowConstructorOptions {
height: height ?? DEFAULT_HEIGHT height: height ?? DEFAULT_HEIGHT
} as BrowserWindowConstructorOptions; } as BrowserWindowConstructorOptions;
if (x != null && y != null) { if (x != null && y != null && State.store.display && screen.getAllDisplays().includes(State.store.display)) {
options.x = x; options.x = x;
options.y = y; options.y = y;
} }
@ -317,6 +318,7 @@ function initWindowBoundsListeners(win: BrowserWindow) {
const saveBounds = () => { const saveBounds = () => {
State.store.windowBounds = win.getBounds(); State.store.windowBounds = win.getBounds();
State.store.display = screen.getDisplayMatching(State.store.windowBounds);
}; };
win.on("resize", saveBounds); win.on("resize", saveBounds);

View file

@ -4,7 +4,7 @@
* Copyright (c) 2023 Vendicated and Vencord contributors * Copyright (c) 2023 Vendicated and Vencord contributors
*/ */
import type { Rectangle } from "electron"; import type { Display, Rectangle } from "electron";
export interface Settings { export interface Settings {
discordBranch?: "stable" | "canary" | "ptb"; discordBranch?: "stable" | "canary" | "ptb";
@ -36,6 +36,7 @@ export interface State {
maximized?: boolean; maximized?: boolean;
minimized?: boolean; minimized?: boolean;
windowBounds?: Rectangle; windowBounds?: Rectangle;
display?: Display;
skippedUpdate?: string; skippedUpdate?: string;
firstLaunch?: boolean; firstLaunch?: boolean;