Ensure mainWindow stays responsive after opening debug logs in fullscreen on MacOS

This commit is contained in:
trevor-signal 2023-08-23 13:39:47 -04:00 committed by GitHub
parent d3a18a197b
commit d4142e10b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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();