feat: enhance window state restoration with screen bounds validation
This commit is contained in:
2
cinny
2
cinny
Submodule cinny updated: 0ddf05746a...fe193bb062
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user