@@ -472,41 +472,52 @@ export class ServerManagerView {
472
472
this . sidebarHoverEvent ( this . $backButton , this . $backTooltip ) ;
473
473
this . sidebarHoverEvent ( this . $dndButton , this . $dndTooltip ) ;
474
474
475
- initDndButton ( ) : void {
476
- const dnd = ConfigUtil . getConfigItem ( "dnd" , false ) ;
477
- this . toggleDndButton ( dnd ) ;
475
+ initDndButton ( ) : void {
476
+ const dnd = ConfigUtil . getConfigItem ( "dnd" , false ) ;
477
+ this . toggleDndButton ( dnd ) ;
478
478
}
479
-
479
+
480
480
getTabIndex ( ) : number {
481
- const currentIndex = this . tabIndex ;
482
- this . tabIndex ++ ;
483
- return currentIndex ;
481
+ const currentIndex = this . tabIndex ;
482
+ this . tabIndex ++ ;
483
+ return currentIndex ;
484
484
}
485
-
485
+
486
486
async getCurrentActiveServer ( ) : Promise < string > {
487
- const tab = this . tabs [ this . activeTabIndex ] ;
488
- return tab instanceof ServerTab ? ( await tab . webview ) . properties . url : "" ;
487
+ const tab = this . tabs [ this . activeTabIndex ] ;
488
+
489
+ if ( tab instanceof ServerTab ) {
490
+ const webview = await tab . webview ;
491
+ return webview ?. properties ?. url ?? "" ;
492
+ }
493
+
494
+ return "" ;
489
495
}
490
-
496
+
491
497
displayInitialCharLogo ( $img : HTMLImageElement , index : number ) : void {
492
- // The index parameter is needed because webview[data-tab-id] can
493
- // increment beyond the size of the sidebar org array and throw an
494
- // error
495
-
496
- const $altIcon = document . createElement ( "div" ) ;
497
- const $parent = $img . parentElement ! ;
498
- const $container = $parent . parentElement ! ;
499
- const webviewId = $container . dataset . tabId ! ;
500
- const $webview = document . querySelector (
501
- `webview[data-tab-id="${ CSS . escape ( webviewId ) } "]` ,
502
- ) ! ;
503
- const realmName = $webview . getAttribute ( "name" ) ;
504
-
505
- if ( realmName === null ) {
506
- $img . src = defaultIcon ;
507
- return ;
508
- }
509
-
498
+ // The index parameter is needed because webview[data-tab-id] can
499
+ // increment beyond the size of the sidebar org array and throw an error
500
+
501
+ const $altIcon = document . createElement ( "div" ) ;
502
+ const $parent = $img . parentElement ;
503
+ if ( ! $parent ) return ;
504
+
505
+ const $container = $parent . parentElement ;
506
+ if ( ! $container ) return ;
507
+
508
+ const webviewId = $container . dataset . tabId ;
509
+ if ( ! webviewId ) return ;
510
+
511
+ const $webview = document . querySelector (
512
+ `webview[data-tab-id="${ CSS . escape ( webviewId ) } "]`
513
+ ) ;
514
+
515
+ if ( ! $webview ) return ;
516
+
517
+ const realmName = $webview . getAttribute ( "name" ) ;
518
+ $img . src = realmName ?? defaultIcon ;
519
+ }
520
+
510
521
$altIcon . textContent = realmName . charAt ( 0 ) || "Z" ;
511
522
$altIcon . classList . add ( "server-icon" ) ;
512
523
$altIcon . classList . add ( "alt-icon" ) ;
0 commit comments