Skip to content

Commit e42fe99

Browse files
committed
Possibly fix #1245
1 parent e57e2d4 commit e42fe99

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

src-main/windows/editor.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -248,23 +248,29 @@ 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
264-
});
265-
if (choice === 1) {
266-
event.preventDefault();
267-
}
251+
this.window.webContents.on('will-prevent-unload', () => {
252+
// Using showMessageBoxSync immediately within the event handler breaks focus on
253+
// Windows - https://github.com/TurboWarp/desktop/issues/1245.
254+
// Instead, we'll let the window refuse the unload, then show our own prompt after
255+
// the event finishes and manually close it ourselves instead of relying on Electron.
256+
queueMicrotask(() => {
257+
const choice = dialog.showMessageBoxSync(this.window, {
258+
title: APP_NAME,
259+
type: 'info',
260+
buttons: [
261+
translate('unload.stay'),
262+
translate('unload.leave')
263+
],
264+
cancelId: 0,
265+
defaultId: 0,
266+
message: translate('unload.message'),
267+
detail: translate('unload.detail'),
268+
noLink: true
269+
});
270+
if (choice === 1) {
271+
this.window.destroy();
272+
}
273+
})
268274
});
269275

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

0 commit comments

Comments
 (0)