Skip to content

Commit a639f9a

Browse files
committed
fix(electron): preserve window bounds on reload
1 parent 7680942 commit a639f9a

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

desktop-app/src/main/main.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let urlToOpen: string | undefined = cli.input[0]?.includes('electronmon')
5050
: cli.input[0];
5151

5252
let mainWindow: BrowserWindow | null = null;
53-
53+
let boundsBeforeReload: Electron.Rectangle | null = null;
5454
initAppMetaHandlers();
5555
initWebviewContextMenu();
5656
initScreenshotHandlers();
@@ -137,7 +137,19 @@ const createWindow = async () => {
137137
});
138138
initDevtoolsHandlers(mainWindow);
139139
initHttpBasicAuthHandlers(mainWindow);
140-
const webPermissionHandlers = WebPermissionHandlers(mainWindow);
140+
ipcMain.on('window-reload', () => {
141+
if (!mainWindow) return;
142+
boundsBeforeReload = mainWindow.getBounds();
143+
mainWindow.webContents.reload();
144+
});
145+
146+
mainWindow.webContents.on('did-finish-load', () => {
147+
if (boundsBeforeReload) {
148+
mainWindow?.setBounds(boundsBeforeReload);
149+
boundsBeforeReload = null;
150+
}
151+
});
152+
141153

142154
// Add BROWSER_SYNC_HOST to the allowed Content-Security-Policy origins
143155
mainWindow.webContents.session.webRequest.onHeadersReceived(

desktop-app/src/main/menu/view.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ const getReloadMenu = (
3030
label: '&Reload',
3131
accelerator: 'CommandOrControl+R',
3232
click: () => {
33-
if (isDev) {
34-
mainWindow.webContents.reload();
35-
return;
36-
}
37-
mainWindow.webContents.send('reload', {});
33+
mainWindow.webContents.send('window-reload');
3834
},
3935
});
4036

0 commit comments

Comments
 (0)