feat: enhance window state restoration with screen bounds validation

This commit is contained in:
2026-04-03 20:47:17 +11:00
parent 7b28d2fcba
commit 42a01c357f
2 changed files with 22 additions and 8 deletions

2
cinny

Submodule cinny updated: 0ddf05746a...fe193bb062

View File

@@ -333,13 +333,27 @@ function getIconPath(iconName) {
function createWindow() { function createWindow() {
// Restore window state or use defaults // Restore window state or use defaults
const windowState = store.get('windowState', { const savedState = store.get('windowState', {});
width: 1280,
height: 905, // Validate saved position is within visible screen bounds
x: undefined, const { screen } = require('electron');
y: undefined, let validPosition = false;
isMaximized: false if (savedState.x !== undefined && savedState.y !== undefined) {
const displays = screen.getAllDisplays();
validPosition = displays.some((display) => {
const { x, y, width, height } = display.workArea;
return savedState.x >= x && savedState.x < x + width &&
savedState.y >= y && savedState.y < y + height;
}); });
}
const windowState = {
width: savedState.width ?? 1280,
height: savedState.height ?? 905,
x: validPosition ? savedState.x : undefined,
y: validPosition ? savedState.y : undefined,
isMaximized: savedState.isMaximized ?? false,
};
mainWindow = new BrowserWindow({ mainWindow = new BrowserWindow({
width: windowState.width, width: windowState.width,