Skip to content

Commit 1029b94

Browse files
authored
Fix broken focus after cancelling unload on Windows (#1250)
1 parent 83453f7 commit 1029b94

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

src-main/windows/editor.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -248,23 +248,31 @@ class EditorWindow extends ProjectRunningWindow {
248248
return this.openedFiles.get(id);
249249
};
250250

251-
this.window.webContents.on('will-prevent-unload', (event) => {
252-
const choice = dialog.showMessageBoxSync(this.window, {
253-
title: APP_NAME,
254-
type: 'info',
255-
buttons: [
256-
translate('unload.stay'),
257-
translate('unload.leave')
258-
],
259-
cancelId: 0,
260-
defaultId: 0,
261-
message: translate('unload.message'),
262-
detail: translate('unload.detail'),
263-
noLink: true
251+
this.window.webContents.on('will-prevent-unload', () => {
252+
// Using showMessageBoxSync synchronously in the event handler causes broken focus on Windows.
253+
// See https://github.com/TurboWarp/desktop/issues/1245
254+
// To work around that, we won't cancel that will-prevent-unload event so the window stays
255+
// open. After a very short delay to let focus get fixed, we'll show a dialog and force close
256+
// the window ourselves if the user wants.
257+
258+
setTimeout(() => {
259+
const choice = dialog.showMessageBoxSync(this.window, {
260+
title: APP_NAME,
261+
type: 'info',
262+
buttons: [
263+
translate('unload.stay'),
264+
translate('unload.leave')
265+
],
266+
cancelId: 0,
267+
defaultId: 0,
268+
message: translate('unload.message'),
269+
detail: translate('unload.detail'),
270+
noLink: true
271+
});
272+
if (choice === 1) {
273+
this.window.destroy();
274+
}
264275
});
265-
if (choice === 1) {
266-
event.preventDefault();
267-
}
268276
});
269277

270278
this.window.on('page-title-updated', (event, title, explicitSet) => {

0 commit comments

Comments
 (0)