1- import { app , screen , type BrowserWindow , type WebContents } from 'electron' ;
1+ import { screen , type BrowserWindow , type WebContents } from 'electron' ;
22import { PAGE_WINDOW_HASH } from '../../shared/constants' ;
33import { IPC_CHANNEL } from '../../shared/ipcChannels' ;
44import type { AppEvent , PageState , Rect } from '../../shared/types' ;
55import { loadEditor } from '../launch/loadEditor' ;
66import { AddressBarFocus } from './AddressBarFocus' ;
7- import { createAppWindow , placeWindow , setUpWindow , syncMenuCheck , trackPlacement } from '../windows' ;
7+ import { createAppWindow , DockOnClose , placeWindow , setUpWindow , syncMenuCheck , trackPlacement } from '../windows' ;
88import { DEFAULT_WINDOW_SIZE , MIN_WINDOW_SIZE , PAGE_WINDOW_MENU_ID , UNTITLED } from './constants' ;
99import { toViewBounds } from './toViewBounds' ;
1010import type { PageWindowDeps } from './types' ;
@@ -24,12 +24,10 @@ export class PageWindow {
2424 /** Saves the website window's bounds at once (they are also saved as it moves). */
2525 private savePlacement : ( ( ) => void ) | undefined ;
2626 private focus : AddressBarFocus | undefined ;
27- /** The app is quitting, and hasn't asked the website window to close yet . */
28- private quitting = false ;
27+ /** Closing the website window puts the website back . */
28+ private readonly close = new DockOnClose ( ( ) => this . detached , ( ) => this . attach ( ) ) ;
2929
30- constructor ( private readonly deps : PageWindowDeps ) {
31- app . on ( 'before-quit' , ( ) => ( this . quitting = this . detached ) ) ;
32- }
30+ constructor ( private readonly deps : PageWindowDeps ) { }
3331
3432 get detached ( ) : boolean {
3533 return this . win !== undefined ;
@@ -64,7 +62,7 @@ export class PageWindow {
6462 this . win = win ;
6563 this . focus = new AddressBarFocus ( win ) ;
6664 this . savePlacement = trackPlacement ( win , store ) ;
67- setUpWindow ( win , { closing : ( ) => this . closing ( ) , maximized : ! ! saved . maximized } ) ;
65+ setUpWindow ( win , { closing : ( ) => this . close . closing ( ) , maximized : ! ! saved . maximized } ) ;
6866 this . moveView ( editor , win ) ;
6967 void store . update ( { detached : true } ) ;
7068 this . announce ( ) ;
@@ -108,21 +106,6 @@ export class PageWindow {
108106 if ( win && ! win . isDestroyed ( ) ) win . destroy ( ) ;
109107 }
110108
111- /**
112- * The website window is asked to close: it puts the website back instead, once the close event is over. Not in a
113- * microtask: that runs before the event returns to Electron, which then goes on with a window destroyed under it
114- * (the app crashed now and then).
115- */
116- private closing ( ) : void {
117- // By the quit: it stays as it is, to go with the editor's window (`dispose`) and open again next time. Should
118- // the editor stay (its drafts couldn't be written), nothing has moved.
119- if ( this . quitting ) {
120- this . quitting = false ;
121- return ;
122- }
123- setImmediate ( ( ) => this . attach ( ) ) ;
124- }
125-
126109 /** Moves the view back into the editor and destroys the website window. Returns whether there was one. */
127110 private putBack ( ) : boolean {
128111 const win = this . win ;
0 commit comments