From 37113b1b4154c2ed60b97e3c503b5d19e1df7c44 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sun, 2 Aug 2026 19:40:18 +0100 Subject: [PATCH] Implement enhanced window management for Windows platform - Introduced syncWindowsWebviewLayout function to ensure webview layout updates with window size changes. - Added applyWindowsStartupWindowState function to manage window state and layout synchronization during startup on Windows. - Updated createMainWindow to call applyWindowsStartupWindowState for improved initial window handling on Windows. --- src/desktop/window.js | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/desktop/window.js b/src/desktop/window.js index ebdedaa..7af88b4 100644 --- a/src/desktop/window.js +++ b/src/desktop/window.js @@ -115,15 +115,36 @@ function broadcastWindowState() { function applyStartupWindowState(window) { if (!window) return - if (isMacOS) { - window.maximize?.() - } else if (process.platform === 'win32') { + if (isMacOS || process.platform === 'win32') { window.maximize?.() } setTimeout(broadcastWindowState, 100) } +function syncWindowsWebviewLayout(window) { + if (!window?.getSize || !window?.setSize) { + return + } + + const { width, height } = window.getSize() + if (!width || !height) { + return + } + + // Re-apply the current size so the native webview relayouts to the window. + window.setSize(width, height) +} + +function applyWindowsStartupWindowState(window) { + if (!window) return + + syncWindowsWebviewLayout(window) + setTimeout(() => syncWindowsWebviewLayout(window), 0) + setTimeout(() => syncWindowsWebviewLayout(window), 100) + setTimeout(broadcastWindowState, 100) +} + function setupWindowEvents(window) { // Electrobun emits resize/focus, not Electron's maximize/fullscreen events. window.on?.('resize', broadcastWindowState) @@ -213,6 +234,11 @@ export async function createMainWindow(rpc) { return new Promise((resolve) => { mainWindow.webview.on('dom-ready', () => { webviewDomReady = true + + if (process.platform === 'win32') { + applyWindowsStartupWindowState(mainWindow) + } + flushPendingNavigations() resolve(mainWindow) })