do window bound checks without relying on displayId
Fixes Vesktop not remembering its position correctly. Seems like the display ids aren't consistent on some windows systems...
This commit is contained in:
@@ -11,6 +11,8 @@ import {
|
||||
Menu,
|
||||
MenuItemConstructorOptions,
|
||||
nativeTheme,
|
||||
Point,
|
||||
Rectangle,
|
||||
screen,
|
||||
session
|
||||
} from "electron";
|
||||
@@ -186,11 +188,21 @@ function getWindowBoundsOptions(): BrowserWindowConstructorOptions {
|
||||
height: height ?? DEFAULT_HEIGHT
|
||||
} as BrowserWindowConstructorOptions;
|
||||
|
||||
const storedDisplay = screen.getAllDisplays().find(display => display.id === State.store.displayId);
|
||||
if (x != null && y != null) {
|
||||
function isInBounds(point: Point, rect: Rectangle) {
|
||||
return (
|
||||
point.x >= rect.x &&
|
||||
point.x <= rect.x + rect.width &&
|
||||
point.y >= rect.y &&
|
||||
point.y <= rect.y + rect.height
|
||||
);
|
||||
}
|
||||
|
||||
if (x != null && y != null && storedDisplay) {
|
||||
options.x = x;
|
||||
options.y = y;
|
||||
const inBounds = screen.getAllDisplays().some(d => isInBounds({ x, y }, d.bounds));
|
||||
if (inBounds) {
|
||||
options.x = x;
|
||||
options.y = y;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Settings.store.disableMinSize) {
|
||||
@@ -236,7 +248,6 @@ function initWindowBoundsListeners(win: BrowserWindow) {
|
||||
|
||||
const saveBounds = () => {
|
||||
State.store.windowBounds = win.getBounds();
|
||||
State.store.displayId = screen.getDisplayMatching(State.store.windowBounds).id;
|
||||
};
|
||||
|
||||
win.on("resize", saveBounds);
|
||||
|
||||
1
src/shared/settings.d.ts
vendored
1
src/shared/settings.d.ts
vendored
@@ -51,7 +51,6 @@ export interface State {
|
||||
maximized?: boolean;
|
||||
minimized?: boolean;
|
||||
windowBounds?: Rectangle;
|
||||
displayId: number;
|
||||
|
||||
firstLaunch?: boolean;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user