Implement enhanced window management for Windows platform
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good
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:
parent
fb81cfedd2
commit
37113b1b41
@ -115,15 +115,36 @@ function broadcastWindowState() {
|
|||||||
function applyStartupWindowState(window) {
|
function applyStartupWindowState(window) {
|
||||||
if (!window) return
|
if (!window) return
|
||||||
|
|
||||||
if (isMacOS) {
|
if (isMacOS || process.platform === 'win32') {
|
||||||
window.maximize?.()
|
|
||||||
} else if (process.platform === 'win32') {
|
|
||||||
window.maximize?.()
|
window.maximize?.()
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(broadcastWindowState, 100)
|
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) {
|
function setupWindowEvents(window) {
|
||||||
// Electrobun emits resize/focus, not Electron's maximize/fullscreen events.
|
// Electrobun emits resize/focus, not Electron's maximize/fullscreen events.
|
||||||
window.on?.('resize', broadcastWindowState)
|
window.on?.('resize', broadcastWindowState)
|
||||||
@ -213,6 +234,11 @@ export async function createMainWindow(rpc) {
|
|||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
mainWindow.webview.on('dom-ready', () => {
|
mainWindow.webview.on('dom-ready', () => {
|
||||||
webviewDomReady = true
|
webviewDomReady = true
|
||||||
|
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
applyWindowsStartupWindowState(mainWindow)
|
||||||
|
}
|
||||||
|
|
||||||
flushPendingNavigations()
|
flushPendingNavigations()
|
||||||
resolve(mainWindow)
|
resolve(mainWindow)
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user