@@ -22,6 +22,7 @@ import {
2222 attachSessionLifecycle ,
2323 decideStartRoute ,
2424 handleConnectIntercept ,
25+ resolveStartRoute ,
2526 tearDownSession ,
2627} from '@/main/session-lifecycle'
2728import { createLauncherShortcutManager } from '@/main/shortcuts'
@@ -48,6 +49,7 @@ function main(): void {
4849 const preloadPath = join ( __dirname , 'preload.cjs' )
4950
5051 let mainWindow : BrowserWindow | null = null
52+ let mainWindowCreation : Promise < void > | null = null
5153 let loadHealth : LoadHealthHandle | null = null
5254 let tray : TrayHandle | null = null
5355 let updater : UpdaterHandle | null = null
@@ -132,8 +134,29 @@ function main(): void {
132134 }
133135
134136 async function createAndLoadMainWindow ( ) : Promise < void > {
137+ if ( mainWindowCreation ) {
138+ await mainWindowCreation
139+ return
140+ }
141+ const pending = performCreateAndLoadMainWindow ( )
142+ mainWindowCreation = pending
143+ try {
144+ await pending
145+ } finally {
146+ if ( mainWindowCreation === pending ) {
147+ mainWindowCreation = null
148+ }
149+ }
150+ }
151+
152+ async function performCreateAndLoadMainWindow ( ) : Promise < void > {
135153 const origin = appOrigin ( )
136154 const ses = configureSessionForOrigin ( origin )
155+ const requestedRoute = decideStartRoute ( config . get ( 'lastRoute' ) )
156+ const route = await resolveStartRoute ( ses , origin , requestedRoute )
157+ if ( route !== requestedRoute ) {
158+ config . set ( 'lastRoute' , route )
159+ }
137160 const win = createMainWindow ( {
138161 config,
139162 events,
@@ -163,7 +186,7 @@ function main(): void {
163186 } )
164187 loadHealth = attachLoadHealth ( win , {
165188 offlinePagePath : OFFLINE_PAGE ,
166- getStartUrl : ( ) => `${ appOrigin ( ) } ${ decideStartRoute ( config . get ( 'lastRoute' ) ) } ` ,
189+ getStartUrl : ( ) => `${ appOrigin ( ) } ${ route } ` ,
167190 isOnline : ( ) => net . isOnline ( ) ,
168191 events,
169192 } )
@@ -178,7 +201,6 @@ function main(): void {
178201 onReauthRequested : ( ) => void authFlow . beginLoginHandoff ( ) ,
179202 } )
180203 loadHealth . startWatchdog ( )
181- const route = decideStartRoute ( config . get ( 'lastRoute' ) )
182204 // Fire-and-forget: the window and all its handlers are wired synchronously
183205 // above, so callers get a usable window immediately and the app menu and
184206 // updater never wait on the remote page's load (load-health surfaces any
0 commit comments