@@ -85,7 +85,7 @@ export class ServerManagerView {
8585 loading : Set < string > ;
8686 activeTab ?: ServerOrFunctionalTab ;
8787 tabs : ServerOrFunctionalTab [ ] ;
88- functionalTabs : Map < TabPage , number > ;
88+ functionalTabs : Map < TabPage , string > ;
8989 presetOrgs : string [ ] ;
9090 preferenceView ?: PreferenceView ;
9191 constructor ( ) {
@@ -195,7 +195,7 @@ export class ServerManagerView {
195195 // eslint-disable-next-line @typescript-eslint/naming-convention
196196 customCSS : false ,
197197 silent : false ,
198- lastActiveTab : 0 ,
198+ lastActiveTabId : undefined ,
199199 dnd : false ,
200200 dndPreviousSettings : {
201201 showNotification : true ,
@@ -343,18 +343,23 @@ export class ServerManagerView {
343343 }
344344
345345 // Open last active tab
346- let lastActiveTab = ConfigUtil . getConfigItem ( "lastActiveTab" , 0 ) ;
347- if ( lastActiveTab >= servers . length ) {
348- lastActiveTab = 0 ;
346+ const firstTab = this . tabs [ 0 ] ;
347+ const lastActiveTabId = ConfigUtil . getConfigItem (
348+ "lastActiveTabId" ,
349+ firstTab . properties . tabId ,
350+ ) ! ;
351+ let lastActiveTab = this . getTabById ( lastActiveTabId ) ! ;
352+ if ( lastActiveTab . properties . index >= servers . length ) {
353+ lastActiveTab = firstTab ;
349354 }
350355
351- // `webview.load()` for lastActiveTab before the others
352- await this . activateTab ( lastActiveTab ) ;
356+ // `webview.load()` for lastActiveTabId before the others
357+ await this . activateTab ( lastActiveTabId ) ;
353358 await Promise . all (
354359 servers . map ( async ( server , i ) => {
355- // After the lastActiveTab is activated, we load the others in the background
360+ // After the lastActiveTabId is activated, we load the others in the background
356361 // without activating them, to prevent flashing of server icons
357- if ( i === lastActiveTab ) {
362+ if ( server . id === lastActiveTabId ) {
358363 return ;
359364 }
360365
@@ -379,7 +384,7 @@ export class ServerManagerView {
379384 icon : DomainUtil . iconAsUrl ( server . icon ) ,
380385 label : server . alias ,
381386 $root : this . $tabsContainer ,
382- onClick : this . activateLastTab . bind ( this , index ) ,
387+ onClick : this . activateLastTab . bind ( this , tabId ) ,
383388 index,
384389 tabId,
385390 onHover : this . onHover . bind ( this , index ) ,
@@ -568,9 +573,8 @@ export class ServerManagerView {
568573 }
569574
570575 const index = this . tabs . length ;
571- this . functionalTabs . set ( tabProperties . page , index ) ;
572-
573576 const tabId = this . generateTabId ( ) ;
577+ this . functionalTabs . set ( tabProperties . page , tabId ) ;
574578 const $view = await tabProperties . makeView ( ) ;
575579 this . $webviewsContainer . append ( $view ) ;
576580
@@ -583,9 +587,9 @@ export class ServerManagerView {
583587 $root : this . $tabsContainer ,
584588 index,
585589 tabId,
586- onClick : this . activateTab . bind ( this , index ) ,
590+ onClick : this . activateTab . bind ( this , tabId ) ,
587591 onDestroy : async ( ) => {
588- await this . destroyFunctionalTab ( tabProperties . page , index ) ;
592+ await this . destroyFunctionalTab ( tabProperties . page , tabId ) ;
589593 tabProperties . destroyView ( ) ;
590594 } ,
591595 $view,
@@ -596,7 +600,7 @@ export class ServerManagerView {
596600 // closed when the functional tab DOM is ready, handled in webview.js
597601 this . $webviewsContainer . classList . remove ( "loaded" ) ;
598602
599- await this . activateTab ( this . functionalTabs . get ( tabProperties . page ) ! ) ;
603+ await this . activateTab ( tabId ) ;
600604 }
601605
602606 async openSettings (
@@ -648,11 +652,11 @@ export class ServerManagerView {
648652 . loadURL ( new URL ( "app/renderer/network.html" , bundleUrl ) . href ) ;
649653 }
650654
651- async activateLastTab ( index : number ) : Promise < void > {
655+ async activateLastTab ( id : string ) : Promise < void > {
652656 // Open all the tabs in background, also activate the tab based on the index
653- await this . activateTab ( index ) ;
657+ await this . activateTab ( id ) ;
654658 // Save last active tab via main process to avoid JSON DB errors
655- ipcRenderer . send ( "save-last-tab" , index ) ;
659+ ipcRenderer . send ( "save-last-tab" , id ) ;
656660 }
657661
658662 // Returns tab in an way that does not crash app when it is passed
@@ -672,8 +676,8 @@ export class ServerManagerView {
672676 return this . tabs . map ( ( tab ) => this . tabForIpc ( tab ) ) ;
673677 }
674678
675- async activateTab ( index : number , hideOldTab = true ) : Promise < void > {
676- const tab = this . tabs [ index ] ;
679+ async activateTab ( id : string , hideOldTab = true ) : Promise < void > {
680+ const tab = this . getTabById ( id ) ;
677681 if ( ! tab ) {
678682 return ;
679683 }
@@ -730,8 +734,8 @@ export class ServerManagerView {
730734 this . $loadingIndicator . classList . toggle ( "hidden" , ! loading ) ;
731735 }
732736
733- async destroyFunctionalTab ( page : TabPage , index : number ) : Promise < void > {
734- const tab = this . tabs [ index ] ;
737+ async destroyFunctionalTab ( page : TabPage , tabId : string ) : Promise < void > {
738+ const tab = this . getTabById ( tabId ) ;
735739 if ( ! tab ) {
736740 return ;
737741 }
@@ -742,15 +746,14 @@ export class ServerManagerView {
742746
743747 const wasActive = tab === this . activeTab ;
744748
749+ delete this . tabs [ tab . properties . index ] ; // eslint-disable-line @typescript-eslint/no-array-delete
745750 await tab . destroy ( ) ;
746-
747- delete this . tabs [ index ] ; // eslint-disable-line @typescript-eslint/no-array-delete
748751 this . functionalTabs . delete ( page ) ;
749752
750753 // Issue #188: If the functional tab was not focused, do not activate another tab.
751754 if ( wasActive ) {
752755 this . activeTab = undefined ;
753- await this . activateTab ( 0 , false ) ;
756+ await this . activateTab ( this . tabs [ 0 ] . properties . tabId , false ) ;
754757 }
755758 }
756759
@@ -772,7 +775,7 @@ export class ServerManagerView {
772775 // Save and remember the index of last active tab so that we can use it later
773776 const { activeTab} = this ;
774777 if ( activeTab !== undefined ) {
775- ConfigUtil . setConfigItem ( "lastActiveTab " , activeTab . properties . index ) ;
778+ ConfigUtil . setConfigItem ( "lastActiveTabId " , activeTab . properties . tabId ) ;
776779 }
777780
778781 // Destroy the current view and re-initiate it
@@ -865,8 +868,8 @@ export class ServerManagerView {
865868 enabled : await this . isLoggedIn ( index ) ,
866869 click : async ( ) => {
867870 // Switch to tab whose icon was right-clicked
868- await this . activateTab ( index ) ;
869871 const tab = this . tabs [ index ] ;
872+ await this . activateTab ( tab . properties . tabId ) ;
870873 if ( tab instanceof ServerTab )
871874 ( await tab . webview ) . showNotificationSettings ( ) ;
872875 } ,
@@ -1020,8 +1023,7 @@ export class ServerManagerView {
10201023 } ) ;
10211024
10221025 ipcRenderer . on ( "switch-server-tab" , async ( event , tabId : string ) => {
1023- const tab = this . getTabById ( tabId ) ! ;
1024- await this . activateLastTab ( tab . properties . index ) ;
1026+ await this . activateLastTab ( tabId ) ;
10251027 } ) ;
10261028
10271029 ipcRenderer . on ( "open-org-tab" , async ( ) => {
0 commit comments