@@ -230,7 +230,7 @@ export class ElectronMainApplication {
230230 this . useNativeWindowFrame = this . getTitleBarStyle ( config ) === 'native' ;
231231 this . _config = config ;
232232 this . hookApplicationEvents ( ) ;
233- this . showInitialWindow ( ) ;
233+ this . showInitialWindow ( argv . includes ( '--open-url' ) ? argv [ argv . length - 1 ] : undefined ) ;
234234 const port = await this . startBackend ( ) ;
235235 this . _backendPort . resolve ( port ) ;
236236 await app . whenReady ( ) ;
@@ -242,9 +242,6 @@ export class ElectronMainApplication {
242242 cwd : process . cwd ( ) ,
243243 secondInstance : false
244244 } ) ;
245- if ( argv . includes ( '--open-url' ) ) {
246- this . openUrl ( argv [ argv . length - 1 ] ) ;
247- }
248245 } ,
249246 ) . parse ( ) ;
250247 }
@@ -321,7 +318,7 @@ export class ElectronMainApplication {
321318 ! ( 'THEIA_ELECTRON_NO_EARLY_WINDOW' in process . env && process . env . THEIA_ELECTRON_NO_EARLY_WINDOW === '1' ) ;
322319 }
323320
324- protected showInitialWindow ( ) : void {
321+ protected showInitialWindow ( urlToOpen : string | undefined ) : void {
325322 if ( this . isShowWindowEarly ( ) || this . isShowSplashScreen ( ) ) {
326323 app . whenReady ( ) . then ( async ( ) => {
327324 const options = await this . getLastWindowOptions ( ) ;
@@ -330,7 +327,11 @@ export class ElectronMainApplication {
330327 options . preventAutomaticShow = true ;
331328 }
332329 this . initialWindow = await this . createWindow ( { ...options } ) ;
333-
330+ TheiaRendererAPI . onApplicationStateChanged ( this . initialWindow . webContents , state => {
331+ if ( state === 'ready' && urlToOpen ) {
332+ this . openUrl ( urlToOpen ) ;
333+ }
334+ } ) ;
334335 if ( this . isShowSplashScreen ( ) ) {
335336 console . log ( 'Showing splash screen' ) ;
336337 this . configureAndShowSplashScreen ( this . initialWindow ) ;
@@ -414,6 +415,7 @@ export class ElectronMainApplication {
414415 options = this . avoidOverlap ( options ) ;
415416 const electronWindow = this . windowFactory ( options , this . config ) ;
416417 const id = electronWindow . window . webContents . id ;
418+ this . activeWindowStack . push ( id ) ;
417419 this . windows . set ( id , electronWindow ) ;
418420 electronWindow . onDidClose ( ( ) => {
419421 const stackIndex = this . activeWindowStack . indexOf ( id ) ;
@@ -429,7 +431,7 @@ export class ElectronMainApplication {
429431 if ( stackIndex >= 0 ) {
430432 this . activeWindowStack . splice ( stackIndex , 1 ) ;
431433 }
432- this . activeWindowStack . push ( id ) ;
434+ this . activeWindowStack . unshift ( id ) ;
433435 TheiaRendererAPI . sendWindowEvent ( electronWindow . window . webContents , 'focus' ) ;
434436 } ) ;
435437 this . attachSaveWindowState ( electronWindow . window ) ;
0 commit comments