Skip to content

Commit 3fc6adf

Browse files
committed
chore: window size and position persistance
1 parent 9296dd3 commit 3fc6adf

2 files changed

Lines changed: 16 additions & 33 deletions

File tree

src-electron/main-window-ipc.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const path = require('path');
33
const { spawn } = require('child_process');
44
const { cleanupWindowTrust } = require('./main-cred-ipc');
55
const { isTrustedOrigin, updateTrustStatus, cleanupTrust, assertTrusted } = require('./ipc-security');
6-
const { DEFAULTS } = require('./window-state');
6+
const { DEFAULTS, trackWindowState } = require('./window-state');
77

88
const PHOENIX_WINDOW_PREFIX = 'phcode-';
99
const PHOENIX_EXTENSION_WINDOW_PREFIX = 'extn-';
@@ -126,6 +126,11 @@ function registerWindowIpcHandlers() {
126126
webPreferences
127127
});
128128

129+
// Track window state for Phoenix windows (not extensions)
130+
if (!isExtension) {
131+
trackWindowState(win);
132+
}
133+
129134
registerWindow(win, label);
130135
await win.loadURL(url);
131136

src-electron/window-state.js

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -142,44 +142,22 @@ function getWindowOptions() {
142142
}
143143

144144
/**
145-
* Track window state changes and save on close.
145+
* Track window state and save on close.
146146
* Call this after creating the BrowserWindow.
147147
*/
148148
function trackWindowState(win) {
149-
let windowState = {
150-
width: DEFAULTS.width,
151-
height: DEFAULTS.height,
152-
x: undefined,
153-
y: undefined,
154-
isMaximized: false
155-
};
156-
157-
// Update state from current window bounds
158-
function updateState() {
159-
if (!win.isMaximized() && !win.isMinimized() && !win.isFullScreen()) {
160-
const bounds = win.getBounds();
161-
windowState.width = bounds.width;
162-
windowState.height = bounds.height;
163-
windowState.x = bounds.x;
164-
windowState.y = bounds.y;
165-
}
166-
windowState.isMaximized = win.isMaximized();
167-
}
168-
169-
// Listen for state changes
170-
win.on('resize', updateState);
171-
win.on('move', updateState);
172-
win.on('maximize', updateState);
173-
win.on('unmaximize', updateState);
174-
175-
// Save state before window closes
176149
win.on('close', () => {
177-
updateState();
150+
// getNormalBounds() returns the non-maximized bounds even when maximized
151+
const bounds = win.getNormalBounds();
152+
const windowState = {
153+
width: bounds.width,
154+
height: bounds.height,
155+
x: bounds.x,
156+
y: bounds.y,
157+
isMaximized: win.isMaximized()
158+
};
178159
saveWindowState(windowState);
179160
});
180-
181-
// Initialize state
182-
updateState();
183161
}
184162

185163
module.exports = {

0 commit comments

Comments
 (0)