Implement enhanced window management for Windows platform
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good

- 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.
This commit is contained in:
Tom Butcher 2026-08-02 19:40:18 +01:00
parent fb81cfedd2
commit 37113b1b41

View File

@ -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)
})