Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Keep the restored window on a connected display

Yugi5c14e965cef4
diff --git a/desktop/changes/offscreen-window.md b/desktop/changes/offscreen-window.md
new file mode 100644
index 0000000000..76f0d4c9bd
--- /dev/null
+++ b/desktop/changes/offscreen-window.md
@@ -0,0 +1 @@
+- Fixed the window opening off-screen when the display it was last on is no longer connected. - @y9ndra
diff --git a/desktop/src/main.ts b/desktop/src/main.ts
index 81bdb5d59c..90a43ef1d2 100644
--- a/desktop/src/main.ts
+++ b/desktop/src/main.ts
@@ -7,6 +7,7 @@ import {
dialog,
nativeTheme,
protocol,
+ screen,
type WebContents,
} from "electron/main";
import serveNextAt from "next-electron-server";
@@ -233,11 +234,26 @@ const windowBounds = () => {
if (userPreferences.get("isWindowMaximized")) return undefined;
const bounds = userPreferences.get("windowBounds");
- if (bounds) return bounds;
+ if (bounds) return fitToDisplay(bounds);
return { width: 1170, height: 710 };
};
+// Saved bounds can point at a display that is no longer connected.
+const fitToDisplay = (bounds: Electron.Rectangle) => {
+ const { workArea } = screen.getDisplayMatching(bounds);
+ const width = Math.min(bounds.width, workArea.width);
+ const height = Math.min(bounds.height, workArea.height);
+ const clamp = (v: number, min: number, max: number) =>
+ Math.min(Math.max(v, min), max);
+ return {
+ x: clamp(bounds.x, workArea.x, workArea.x + workArea.width - width),
+ y: clamp(bounds.y, workArea.y, workArea.y + workArea.height - height),
+ width,
+ height,
+ };
+};
+
const minimumWindowSize = () => ({ minWidth: 200, minHeight: 200 });
const saveWindowBounds = (window: BrowserWindow) => {