From 0a2c75fd8ba5595c57cb06ade11bd201713f9b22 Mon Sep 17 00:00:00 2001 From: Sucukdeluxe <259325684+Sucukdeluxe@users.noreply.github.com> Date: Sat, 26 Sep 2026 10:18:59 +0200 Subject: [PATCH] Re-layout window content after the first show when sizes disagree On remote desktop sessions the web contents could appear offset with white borders until the next start. After the window is shown, compare the renderer viewport with the content size and force one relayout on a mismatch or in an RDP session. The measured values are logged. --- main.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/main.js b/main.js index bf92fe9..1e35801 100644 --- a/main.js +++ b/main.js @@ -1549,6 +1549,27 @@ async function runHosterHealthCheck(config, requestedChecks, onResult = null) { return { checkedAt: new Date().toISOString(), results }; } +async function settleWindowContentAfterShow(window) { + if (!window || window.isDestroyed() || window.isMinimized() || window.isMaximized() || window.isFullScreen()) return; + let viewport = null; + try { + viewport = await window.webContents.executeJavaScript('[window.innerWidth, window.innerHeight]'); + } catch {} + if (window.isDestroyed()) return; + const [contentWidth, contentHeight] = window.getContentSize(); + const zoom = window.webContents.getZoomFactor() || 1; + const measured = Array.isArray(viewport) && viewport.length === 2; + const mismatch = !measured + || Math.abs(Math.round(viewport[0] * zoom) - contentWidth) > 2 + || Math.abs(Math.round(viewport[1] * zoom) - contentHeight) > 2; + const remoteSession = process.platform === 'win32' && /^RDP-/i.test(process.env.SESSIONNAME || ''); + logInfo(`window-content: viewport=${measured ? viewport.join('x') : 'unknown'} content=${contentWidth}x${contentHeight} zoom=${zoom} rdp=${remoteSession}`); + if (!mismatch && !remoteSession) return; + const bounds = window.getBounds(); + window.setBounds({ ...bounds, width: bounds.width + 1 }); + window.setBounds(bounds); +} + function createWindow() { const startupWindow = createStartupWindow(BrowserWindow, { title: 'Multi Hoster Uploader', @@ -1591,6 +1612,10 @@ function createWindow() { }); mainWindow.webContents.setBackgroundThrottling(false); + const shownWindow = mainWindow; + mainWindow.once('show', () => { + setTimeout(() => { void settleWindowContentAfterShow(shownWindow); }, 250); + }); mainWindow.webContents.on('did-start-navigation', (_event, _url, isInPlace, isMainFrame) => { if (isInPlace || !isMainFrame) return;