@@ -86,7 +86,6 @@ export class ServerManagerView {
8686 activeTabIndex : number ;
8787 tabs : ServerOrFunctionalTab [ ] ;
8888 functionalTabs : Map < TabPage , number > ;
89- tabId : number ;
9089 presetOrgs : string [ ] ;
9190 preferenceView ?: PreferenceView ;
9291 constructor ( ) {
@@ -132,7 +131,6 @@ export class ServerManagerView {
132131 this . tabs = [ ] ;
133132 this . presetOrgs = [ ] ;
134133 this . functionalTabs = new Map ( ) ;
135- this . tabId = 0 ;
136134 }
137135
138136 async init ( ) : Promise < void > {
@@ -375,7 +373,7 @@ export class ServerManagerView {
375373 }
376374
377375 initServer ( server : ServerConfig , index : number ) : ServerTab {
378- const tabId = this . gettabId ( ) ;
376+ const tabId = this . generateTabId ( ) ;
379377 const tab : ServerTab = new ServerTab ( {
380378 role : "server" ,
381379 icon : DomainUtil . iconAsUrl ( server . icon ) ,
@@ -384,6 +382,7 @@ export class ServerManagerView {
384382 onClick : this . activateLastTab . bind ( this , index ) ,
385383 index,
386384 tabId,
385+ serverId : server . id ,
387386 onHover : this . onHover . bind ( this , index ) ,
388387 onHoverOut : this . onHoverOut . bind ( this , index ) ,
389388 webview : WebView . create ( {
@@ -483,10 +482,8 @@ export class ServerManagerView {
483482 this . toggleDndButton ( dnd ) ;
484483 }
485484
486- gettabId ( ) : number {
487- const currentIndex = this . tabId ;
488- this . tabId ++ ;
489- return currentIndex ;
485+ generateTabId ( ) : string {
486+ return DomainUtil . generateDomainId ( ) ;
490487 }
491488
492489 async getCurrentActiveServer ( ) : Promise < string > {
@@ -574,7 +571,7 @@ export class ServerManagerView {
574571 const index = this . tabs . length ;
575572 this . functionalTabs . set ( tabProperties . page , index ) ;
576573
577- const tabId = this . gettabId ( ) ;
574+ const tabId = this . generateTabId ( ) ;
578575 const $view = await tabProperties . makeView ( ) ;
579576 this . $webviewsContainer . append ( $view ) ;
580577
@@ -669,6 +666,7 @@ export class ServerManagerView {
669666 page : tab . properties . page ,
670667 label : tab . properties . label ,
671668 index : tab . properties . index ,
669+ id : tab . properties . tabId ,
672670 } ) ) ;
673671 }
674672
@@ -811,14 +809,21 @@ export class ServerManagerView {
811809 }
812810 }
813811
814- async isLoggedIn ( tabId : number ) : Promise < boolean > {
815- const tab = this . tabs [ tabId ] ;
812+ async isLoggedIn ( index : number ) : Promise < boolean > {
813+ const tab = this . tabs [ index ] ;
816814 if ( ! ( tab instanceof ServerTab ) ) return false ;
817815 const webview = await tab . webview ;
818816 const url = webview . getWebContents ( ) . getURL ( ) ;
819817 return ! ( url . endsWith ( "/login/" ) || webview . loading ) ;
820818 }
821819
820+ getTabByServerId ( serverId : string ) : ServerTab | undefined {
821+ return this . tabs . find (
822+ ( tab ) : tab is ServerTab =>
823+ tab instanceof ServerTab && tab . serverId === serverId ,
824+ ) ;
825+ }
826+
822827 addContextMenu ( $serverImg : HTMLElement , index : number ) : void {
823828 $serverImg . addEventListener ( "contextmenu" , async ( event ) => {
824829 event . preventDefault ( ) ;
@@ -1005,8 +1010,9 @@ export class ServerManagerView {
10051010 ipcRenderer . send ( "reload-full-app" ) ;
10061011 } ) ;
10071012
1008- ipcRenderer . on ( "switch-server-tab" , async ( event , index : number ) => {
1009- await this . activateLastTab ( index ) ;
1013+ ipcRenderer . on ( "switch-server-tab" , async ( event , serverId : string ) => {
1014+ const tab = this . getTabByServerId ( serverId ) ! ;
1015+ await this . activateLastTab ( tab . properties . index ) ;
10101016 } ) ;
10111017
10121018 ipcRenderer . on ( "open-org-tab" , async ( ) => {
0 commit comments