@@ -77,7 +77,6 @@ let updateChecker
7777let currentTrayIconPath = null
7878let currentTrayMenuTemplate = null
7979let trayUpdateIntervalObj = null
80- let skipStrictCloseGuard = false // to allow window closing in strict mode when we want to close it
8180
8281log . initialize ( { preload : true } )
8382
@@ -444,12 +443,18 @@ function startPowerMonitoring () {
444443
445444function closeWindows ( windowArray ) {
446445 for ( const window of windowArray ) {
446+ if ( ! window || window . isDestroyed ( ) ) {
447+ continue
448+ }
449+
447450 window . hide ( )
448451 if ( windowArray [ 0 ] === window ) {
449452 ipcMain . removeHandler ( 'send-long-break-data' )
450453 ipcMain . removeHandler ( 'send-mini-break-data' )
451454 }
452- window . close ( )
455+
456+ // Use destroy() for immediate, guaranteed cleanup on all platforms
457+ window . destroy ( )
453458 }
454459 return null
455460}
@@ -781,7 +786,6 @@ function startMicrobreak () {
781786 microbreakWinLocal . setAlwaysOnTop ( ! showBreaksAsRegularWindows , 'pop-up-menu' )
782787 if ( microbreakWinLocal ) {
783788 microbreakWinLocal . on ( 'close' , ( e ) => {
784- if ( skipStrictCloseGuard ) return
785789 if ( breakPlanner . scheduler . timeLeft > 0 && settings . get ( 'microbreakStrictMode' ) ) {
786790 log . info ( 'Stretchly: preventing closing break window as in strict mode' )
787791 e . preventDefault ( )
@@ -937,7 +941,6 @@ function startBreak () {
937941 breakWinLocal . setAlwaysOnTop ( ! showBreaksAsRegularWindows , 'pop-up-menu' )
938942 if ( breakWinLocal ) {
939943 breakWinLocal . on ( 'close' , ( e ) => {
940- if ( skipStrictCloseGuard ) return
941944 if ( breakPlanner . scheduler . timeLeft > 0 && settings . get ( 'breakStrictMode' ) ) {
942945 log . info ( 'Stretchly: preventing closing break window as in strict mode' )
943946 e . preventDefault ( )
@@ -975,10 +978,7 @@ function breakComplete (shouldPlaySound, windows, breakType) {
975978 // get focus on the last app
976979 Menu . sendActionToFirstResponder ( 'hide:' )
977980 }
978- skipStrictCloseGuard = true
979- const result = closeWindows ( windows )
980- skipStrictCloseGuard = false
981- return result
981+ return closeWindows ( windows )
982982}
983983
984984function enterManualAwaitPhase ( type , shouldPlaySound ) {
0 commit comments