From d4142e10b8e20f0cb35eafd49432a9cc54487fc8 Mon Sep 17 00:00:00 2001 From: trevor-signal <131492920+trevor-signal@users.noreply.github.com> Date: Wed, 23 Aug 2023 13:39:47 -0400 Subject: [PATCH] Ensure mainWindow stays responsive after opening debug logs in fullscreen on MacOS --- app/main.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/app/main.ts b/app/main.ts index f28ac14756..382ab2c34b 100644 --- a/app/main.ts +++ b/app/main.ts @@ -1375,13 +1375,28 @@ async function openArtCreator() { let debugLogWindow: BrowserWindow | undefined; async function showDebugLogWindow() { if (debugLogWindow) { - debugLogWindow.show(); + doShowDebugLogWindow(); return; } + function doShowDebugLogWindow() { + if (debugLogWindow) { + // Electron has [a macOS bug][0] that causes parent windows to become unresponsive + // if it's fullscreen and opens a fullscreen child window. Until that's fixed, we + // only set the parent on MacOS is if the mainWindow is not fullscreen + // [0]: https://github.com/electron/electron/issues/32374 + if (OS.isMacOS() && mainWindow?.isFullScreen()) { + debugLogWindow.setParentWindow(null); + } else { + debugLogWindow.setParentWindow(mainWindow ?? null); + } + debugLogWindow.show(); + } + } + const titleBarOverlay = await getTitleBarOverlay(); - const options = { + const options: Electron.BrowserWindowConstructorOptions = { width: 700, height: 500, resizable: false, @@ -1398,14 +1413,8 @@ async function showDebugLogWindow() { sandbox: true, contextIsolation: true, preload: join(__dirname, '../bundles/debuglog/preload.js'), - nativeWindowOpen: true, }, parent: mainWindow, - // Electron has [a macOS bug][0] that causes parent windows to become unresponsive if - // it's fullscreen and opens a fullscreen child window. Until that's fixed, we - // prevent the child window from being fullscreenable, which sidesteps the problem. - // [0]: https://github.com/electron/electron/issues/32374 - fullscreenable: !OS.isMacOS(), }; debugLogWindow = new BrowserWindow(options); @@ -1418,7 +1427,7 @@ async function showDebugLogWindow() { debugLogWindow.once('ready-to-show', () => { if (debugLogWindow) { - debugLogWindow.show(); + doShowDebugLogWindow(); // Electron sometimes puts the window in a strange spot until it's shown. debugLogWindow.center();