Skip to content

Commit 78b139b

Browse files
committed
Fix null checks and error handling in displayInitialCharLogo
1 parent 9f5a3b4 commit 78b139b

File tree

1 file changed

+40
-29
lines changed

1 file changed

+40
-29
lines changed

app/renderer/js/main.ts

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -472,41 +472,52 @@ export class ServerManagerView {
472472
this.sidebarHoverEvent(this.$backButton, this.$backTooltip);
473473
this.sidebarHoverEvent(this.$dndButton, this.$dndTooltip);
474474

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);
478478
}
479-
479+
480480
getTabIndex(): number {
481-
const currentIndex = this.tabIndex;
482-
this.tabIndex++;
483-
return currentIndex;
481+
const currentIndex = this.tabIndex;
482+
this.tabIndex++;
483+
return currentIndex;
484484
}
485-
485+
486486
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 "";
489495
}
490-
496+
491497
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+
510521
$altIcon.textContent = realmName.charAt(0) || "Z";
511522
$altIcon.classList.add("server-icon");
512523
$altIcon.classList.add("alt-icon");

0 commit comments

Comments
 (0)