File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -248,13 +248,21 @@ class EditorWindow extends ProjectRunningWindow {
248248 return this . openedFiles . get ( id ) ;
249249 } ;
250250
251+ let processingWillPreventUnload = false ;
251252 this . window . webContents . on ( 'will-prevent-unload' , ( ) => {
252253 // Using showMessageBoxSync synchronously in the event handler causes broken focus on Windows.
253254 // See https://github.com/TurboWarp/desktop/issues/1245
254255 // To work around that, we won't cancel that will-prevent-unload event so the window stays
255256 // open. After a very short delay to let focus get fixed, we'll show a dialog and force close
256257 // the window ourselves if the user wants.
257258
259+ // Due to the timeout, this event could theoretically fire multiple times before we show the
260+ // dialog. Make sure to only show one dialog if that happens.
261+ if ( processingWillPreventUnload ) {
262+ return ;
263+ }
264+ processingWillPreventUnload = true ;
265+
258266 setTimeout ( ( ) => {
259267 const choice = dialog . showMessageBoxSync ( this . window , {
260268 title : APP_NAME ,
@@ -272,6 +280,7 @@ class EditorWindow extends ProjectRunningWindow {
272280 if ( choice === 1 ) {
273281 this . window . destroy ( ) ;
274282 }
283+ processingWillPreventUnload = false ;
275284 } ) ;
276285 } ) ;
277286
You can’t perform that action at this time.
0 commit comments