@@ -82,37 +82,14 @@ export class DefaultSecondaryWindowService implements SecondaryWindowService {
8282 }
8383
8484 createSecondaryWindow ( widget : ExtractableWidget , shell : ApplicationShell ) : Window | undefined {
85- const win = this . doCreateSecondaryWindow ( widget , shell ) ;
86- if ( win ) {
87- this . secondaryWindows . push ( win ) ;
88- win . addEventListener ( 'close' , ( ) => {
89- const extIndex = this . secondaryWindows . indexOf ( win ) ;
90- if ( extIndex > - 1 ) {
91- this . secondaryWindows . splice ( extIndex , 1 ) ;
92- } ;
93- } ) ;
94- }
95- return win ;
96- }
97-
98- protected findWindow < T > ( windowName : string ) : Window | undefined {
99- for ( const w of this . secondaryWindows ) {
100- if ( w . name === windowName ) {
101- return w ;
102- }
103- }
104- return undefined ;
105- }
106-
107- protected doCreateSecondaryWindow ( widget : ExtractableWidget , shell : ApplicationShell ) : Window | undefined {
108- let options ;
10985 const [ height , width , left , top ] = this . findSecondaryWindowCoordinates ( widget ) ;
110- options = `popup=1,width=${ width } ,height=${ height } ,left=${ left } ,top=${ top } ` ;
86+ let options = `popup=1,width=${ width } ,height=${ height } ,left=${ left } ,top=${ top } ` ;
11187 if ( this . preferenceService . get ( 'window.secondaryWindowAlwaysOnTop' ) ) {
11288 options += ',alwaysOnTop=true' ;
11389 }
11490 const newWindow = window . open ( DefaultSecondaryWindowService . SECONDARY_WINDOW_URL , this . nextWindowId ( ) , options ) ?? undefined ;
11591 if ( newWindow ) {
92+ this . secondaryWindows . push ( newWindow ) ;
11693 newWindow . addEventListener ( 'DOMContentLoaded' , ( ) => {
11794 newWindow . addEventListener ( 'beforeunload' , evt => {
11895 const saveable = Saveable . get ( widget ) ;
@@ -124,17 +101,38 @@ export class DefaultSecondaryWindowService implements SecondaryWindowService {
124101 }
125102 } , { capture : true } ) ;
126103
127- newWindow . addEventListener ( 'close ' , ( ) => {
104+ newWindow . addEventListener ( 'unload ' , ( ) => {
128105 const saveable = Saveable . get ( widget ) ;
129106 shell . closeWidget ( widget . id , {
130107 save : ! ! saveable && saveable . dirty && saveable . autoSave !== 'off'
131108 } ) ;
109+
110+ const extIndex = this . secondaryWindows . indexOf ( newWindow ) ;
111+ if ( extIndex > - 1 ) {
112+ this . secondaryWindows . splice ( extIndex , 1 ) ;
113+ } ;
132114 } ) ;
115+ this . windowCreated ( newWindow , widget , shell ) ;
133116 } ) ;
134117 }
135118 return newWindow ;
136119 }
137120
121+ protected windowCreated ( newWindow : Window , widget : ExtractableWidget , shell : ApplicationShell ) : void {
122+ newWindow . addEventListener ( 'unload' , ( ) => {
123+ shell . closeWidget ( widget . id ) ;
124+ } ) ;
125+ }
126+
127+ protected findWindow < T > ( windowName : string ) : Window | undefined {
128+ for ( const w of this . secondaryWindows ) {
129+ if ( w . name === windowName ) {
130+ return w ;
131+ }
132+ }
133+ return undefined ;
134+ }
135+
138136 protected findSecondaryWindowCoordinates ( widget : ExtractableWidget ) : ( number | undefined ) [ ] {
139137 const clientBounds = widget . node . getBoundingClientRect ( ) ;
140138 const preference = this . preferenceService . get ( 'window.secondaryWindowPlacement' ) ;
0 commit comments