@@ -24,6 +24,7 @@ import { updater } from "./updater";
2424
2525export type WindowOpts = {
2626 unamePlatform : string ;
27+ isPrimaryStartupWindow ?: boolean ;
2728} ;
2829
2930const MIN_WINDOW_WIDTH = 800 ;
@@ -36,6 +37,7 @@ export const waveWindowMap = new Map<string, WaveBrowserWindow>(); // waveWindow
3637export let focusedWaveWindow : WaveBrowserWindow = null ;
3738
3839let cachedClientId : string = null ;
40+ let hasCompletedFirstRelaunch = false ;
3941
4042async function getClientId ( ) {
4143 if ( cachedClientId != null ) {
@@ -51,6 +53,7 @@ type WindowActionQueueEntry =
5153 op : "switchtab" ;
5254 tabId : string ;
5355 setInBackend : boolean ;
56+ primaryStartupTab ?: boolean ;
5457 }
5558 | {
5659 op : "createtab" ;
@@ -346,31 +349,35 @@ export class WaveBrowserWindow extends BaseWindow {
346349 await this . _queueActionInternal ( { op : "switchworkspace" , workspaceId } ) ;
347350 }
348351
349- async setActiveTab ( tabId : string , setInBackend : boolean ) {
350- console . log ( "setActiveTab" , tabId , this . waveWindowId , this . workspaceId , setInBackend ) ;
351- await this . _queueActionInternal ( { op : "switchtab" , tabId, setInBackend } ) ;
352+ async setActiveTab ( tabId : string , setInBackend : boolean , primaryStartupTab = false ) {
353+ console . log ( "setActiveTab" , tabId , this . waveWindowId , this . workspaceId , setInBackend , primaryStartupTab ? "(primary startup)" : "" ) ;
354+ await this . _queueActionInternal ( { op : "switchtab" , tabId, setInBackend, primaryStartupTab } ) ;
352355 }
353356
354- private async initializeTab ( tabView : WaveTabView ) {
357+ private async initializeTab ( tabView : WaveTabView , primaryStartupTab : boolean ) {
355358 const clientId = await getClientId ( ) ;
356359 await tabView . initPromise ;
357360 this . contentView . addChildView ( tabView ) ;
358- const initOpts = {
361+ const initOpts : WaveInitOpts = {
359362 tabId : tabView . waveTabId ,
360363 clientId : clientId ,
361364 windowId : this . waveWindowId ,
362365 activate : true ,
363366 } ;
367+ if ( primaryStartupTab ) {
368+ initOpts . primaryTabStartup = true ;
369+ }
364370 tabView . savedInitOpts = { ...initOpts } ;
365371 tabView . savedInitOpts . activate = false ;
372+ delete tabView . savedInitOpts . primaryTabStartup ;
366373 let startTime = Date . now ( ) ;
367- console . log ( "before wave ready, init tab, sending wave-init" , tabView . waveTabId ) ;
374+ console . log ( "before wave ready, init tab, sending wave-init" , tabView . waveTabId , primaryStartupTab ? "(primary startup)" : "" ) ;
368375 tabView . webContents . send ( "wave-init" , initOpts ) ;
369376 await tabView . waveReadyPromise ;
370377 console . log ( "wave-ready init time" , Date . now ( ) - startTime + "ms" ) ;
371378 }
372379
373- private async setTabViewIntoWindow ( tabView : WaveTabView , tabInitialized : boolean ) {
380+ private async setTabViewIntoWindow ( tabView : WaveTabView , tabInitialized : boolean , primaryStartupTab = false ) {
374381 if ( this . activeTabView == tabView ) {
375382 return ;
376383 }
@@ -382,8 +389,8 @@ export class WaveBrowserWindow extends BaseWindow {
382389 this . activeTabView = tabView ;
383390 this . allLoadedTabViews . set ( tabView . waveTabId , tabView ) ;
384391 if ( ! tabInitialized ) {
385- console . log ( "initializing a new tab" ) ;
386- const p1 = this . initializeTab ( tabView ) ;
392+ console . log ( "initializing a new tab" , primaryStartupTab ? "(primary startup)" : "" ) ;
393+ const p1 = this . initializeTab ( tabView , primaryStartupTab ) ;
387394 const p2 = this . repositionTabsSlowly ( 100 ) ;
388395 await Promise . all ( [ p1 , p2 ] ) ;
389396 } else {
@@ -541,7 +548,8 @@ export class WaveBrowserWindow extends BaseWindow {
541548 return ;
542549 }
543550 const [ tabView , tabInitialized ] = await getOrCreateWebViewForTab ( this . waveWindowId , tabId ) ;
544- await this . setTabViewIntoWindow ( tabView , tabInitialized ) ;
551+ const primaryStartupTabFlag = entry . op === "switchtab" ? entry . primaryStartupTab ?? false : false ;
552+ await this . setTabViewIntoWindow ( tabView , tabInitialized , primaryStartupTabFlag ) ;
545553 } catch ( e ) {
546554 console . log ( "error caught in processActionQueue" , e ) ;
547555 } finally {
@@ -628,6 +636,7 @@ export async function createWindowForWorkspace(workspaceId: string) {
628636 }
629637 const newBwin = await createBrowserWindow ( newWin , await RpcApi . GetFullConfigCommand ( ElectronWshClient ) , {
630638 unamePlatform,
639+ isPrimaryStartupWindow : false ,
631640 } ) ;
632641 newBwin . show ( ) ;
633642}
@@ -653,7 +662,7 @@ export async function createBrowserWindow(
653662 console . log ( "createBrowserWindow" , waveWindow . oid , workspace . oid , workspace ) ;
654663 const bwin = new WaveBrowserWindow ( waveWindow , fullConfig , opts ) ;
655664 if ( workspace . activetabid ) {
656- await bwin . setActiveTab ( workspace . activetabid , false ) ;
665+ await bwin . setActiveTab ( workspace . activetabid , false , opts . isPrimaryStartupWindow ?? false ) ;
657666 }
658667 return bwin ;
659668}
@@ -764,7 +773,10 @@ export async function createNewWaveWindow() {
764773 const existingWindowId = clientData . windowids [ 0 ] ;
765774 const existingWindowData = ( await ObjectService . GetObject ( "window:" + existingWindowId ) ) as WaveWindow ;
766775 if ( existingWindowData != null ) {
767- const win = await createBrowserWindow ( existingWindowData , fullConfig , { unamePlatform } ) ;
776+ const win = await createBrowserWindow ( existingWindowData , fullConfig , {
777+ unamePlatform,
778+ isPrimaryStartupWindow : false ,
779+ } ) ;
768780 win . show ( ) ;
769781 recreatedWindow = true ;
770782 }
@@ -774,7 +786,10 @@ export async function createNewWaveWindow() {
774786 return ;
775787 }
776788 console . log ( "creating new window" ) ;
777- const newBrowserWindow = await createBrowserWindow ( null , fullConfig , { unamePlatform } ) ;
789+ const newBrowserWindow = await createBrowserWindow ( null , fullConfig , {
790+ unamePlatform,
791+ isPrimaryStartupWindow : false ,
792+ } ) ;
778793 newBrowserWindow . show ( ) ;
779794}
780795
@@ -793,18 +808,26 @@ export async function relaunchBrowserWindows() {
793808
794809 const clientData = await ClientService . GetClientData ( ) ;
795810 const fullConfig = await RpcApi . GetFullConfigCommand ( ElectronWshClient ) ;
811+ const windowIds = clientData . windowids ?? [ ] ;
796812 const wins : WaveBrowserWindow [ ] = [ ] ;
797- for ( const windowId of clientData . windowids . slice ( ) . reverse ( ) ) {
813+ const isFirstRelaunch = ! hasCompletedFirstRelaunch ;
814+ const primaryWindowId = windowIds . length > 0 ? windowIds [ 0 ] : null ;
815+ for ( const windowId of windowIds . slice ( ) . reverse ( ) ) {
798816 const windowData : WaveWindow = await WindowService . GetWindow ( windowId ) ;
799817 if ( windowData == null ) {
800818 console . log ( "relaunch -- window data not found, closing window" , windowId ) ;
801819 await WindowService . CloseWindow ( windowId , true ) ;
802820 continue ;
803821 }
804- console . log ( "relaunch -- creating window" , windowId , windowData ) ;
805- const win = await createBrowserWindow ( windowData , fullConfig , { unamePlatform } ) ;
822+ const isPrimaryStartupWindow = isFirstRelaunch && windowId === primaryWindowId ;
823+ console . log ( "relaunch -- creating window" , windowId , windowData , isPrimaryStartupWindow ? "(primary startup)" : "" ) ;
824+ const win = await createBrowserWindow ( windowData , fullConfig , {
825+ unamePlatform,
826+ isPrimaryStartupWindow
827+ } ) ;
806828 wins . push ( win ) ;
807829 }
830+ hasCompletedFirstRelaunch = true ;
808831 for ( const win of wins ) {
809832 console . log ( "show window" , win . waveWindowId ) ;
810833 win . show ( ) ;
0 commit comments