From e42fe99cff5ed59365484ac3d74f4ea9c8d9a33f Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Mon, 29 Sep 2025 20:03:12 -0500 Subject: [PATCH 1/4] Possibly fix https://github.com/TurboWarp/desktop/issues/1245 --- src-main/windows/editor.js | 40 ++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src-main/windows/editor.js b/src-main/windows/editor.js index eedbea1b..f084728a 100644 --- a/src-main/windows/editor.js +++ b/src-main/windows/editor.js @@ -248,23 +248,29 @@ class EditorWindow extends ProjectRunningWindow { return this.openedFiles.get(id); }; - this.window.webContents.on('will-prevent-unload', (event) => { - const choice = dialog.showMessageBoxSync(this.window, { - title: APP_NAME, - type: 'info', - buttons: [ - translate('unload.stay'), - translate('unload.leave') - ], - cancelId: 0, - defaultId: 0, - message: translate('unload.message'), - detail: translate('unload.detail'), - noLink: true - }); - if (choice === 1) { - event.preventDefault(); - } + this.window.webContents.on('will-prevent-unload', () => { + // Using showMessageBoxSync immediately within the event handler breaks focus on + // Windows - https://github.com/TurboWarp/desktop/issues/1245. + // Instead, we'll let the window refuse the unload, then show our own prompt after + // the event finishes and manually close it ourselves instead of relying on Electron. + queueMicrotask(() => { + const choice = dialog.showMessageBoxSync(this.window, { + title: APP_NAME, + type: 'info', + buttons: [ + translate('unload.stay'), + translate('unload.leave') + ], + cancelId: 0, + defaultId: 0, + message: translate('unload.message'), + detail: translate('unload.detail'), + noLink: true + }); + if (choice === 1) { + this.window.destroy(); + } + }) }); this.window.on('page-title-updated', (event, title, explicitSet) => { From 370c8d6e5e871d45cd18d4ef0d40f90ee026ba64 Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Fri, 10 Oct 2025 19:55:51 -0500 Subject: [PATCH 2/4] make it actually work --- src-main/windows/editor.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src-main/windows/editor.js b/src-main/windows/editor.js index f084728a..02d9c2ec 100644 --- a/src-main/windows/editor.js +++ b/src-main/windows/editor.js @@ -249,11 +249,12 @@ class EditorWindow extends ProjectRunningWindow { }; this.window.webContents.on('will-prevent-unload', () => { - // Using showMessageBoxSync immediately within the event handler breaks focus on - // Windows - https://github.com/TurboWarp/desktop/issues/1245. - // Instead, we'll let the window refuse the unload, then show our own prompt after - // the event finishes and manually close it ourselves instead of relying on Electron. - queueMicrotask(() => { + // Using showMessageBoxSync synchronously in the event handler causes broken focus on Windows. + // See https://github.com/TurboWarp/desktop/issues/1245 + // To work around that, we'll let the will-prevent-unload event happen so the window stays open, + // then show our own prompt after a very short delay so that window focus doesn't break. + + setTimeout(() => { const choice = dialog.showMessageBoxSync(this.window, { title: APP_NAME, type: 'info', @@ -270,7 +271,7 @@ class EditorWindow extends ProjectRunningWindow { if (choice === 1) { this.window.destroy(); } - }) + }); }); this.window.on('page-title-updated', (event, title, explicitSet) => { From 401a49054a96819f236256e47c02e1f742607c95 Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Fri, 10 Oct 2025 19:58:15 -0500 Subject: [PATCH 3/4] upd commens --- src-main/windows/editor.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src-main/windows/editor.js b/src-main/windows/editor.js index 02d9c2ec..e8f697c7 100644 --- a/src-main/windows/editor.js +++ b/src-main/windows/editor.js @@ -251,8 +251,9 @@ class EditorWindow extends ProjectRunningWindow { this.window.webContents.on('will-prevent-unload', () => { // Using showMessageBoxSync synchronously in the event handler causes broken focus on Windows. // See https://github.com/TurboWarp/desktop/issues/1245 - // To work around that, we'll let the will-prevent-unload event happen so the window stays open, - // then show our own prompt after a very short delay so that window focus doesn't break. + // To work around that, we'll won't cancel that will-prevent-unload event so the window stays + // open. After a very short delay to let focus get fixed, we'll show the dialog and force close + // the window ourselves if the user wants. setTimeout(() => { const choice = dialog.showMessageBoxSync(this.window, { From 81eb06e5a48d75fc127db111eb0b907821a1c390 Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Fri, 10 Oct 2025 19:59:00 -0500 Subject: [PATCH 4/4] a --- src-main/windows/editor.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src-main/windows/editor.js b/src-main/windows/editor.js index e8f697c7..b280ebbd 100644 --- a/src-main/windows/editor.js +++ b/src-main/windows/editor.js @@ -251,8 +251,8 @@ class EditorWindow extends ProjectRunningWindow { this.window.webContents.on('will-prevent-unload', () => { // Using showMessageBoxSync synchronously in the event handler causes broken focus on Windows. // See https://github.com/TurboWarp/desktop/issues/1245 - // To work around that, we'll won't cancel that will-prevent-unload event so the window stays - // open. After a very short delay to let focus get fixed, we'll show the dialog and force close + // To work around that, we won't cancel that will-prevent-unload event so the window stays + // open. After a very short delay to let focus get fixed, we'll show a dialog and force close // the window ourselves if the user wants. setTimeout(() => {