Skip to content

Commit f28afbb

Browse files
committed
app: Don't access tabs by index.
This commit removes miscallenous instances of accessing tabs directly by the index.
1 parent 73fd8b4 commit f28afbb

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

app/main/menu.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,6 @@ function getWindowSubmenu(
313313
type: "separator",
314314
});
315315
for (const tab of tabs) {
316-
// Skip missing elements left by `delete this.tabs[index]` in
317-
// ServerManagerView.
318316
if (tab === undefined) continue;
319317

320318
// Do not add functional tab settings to list of windows in menu bar

app/renderer/js/components/webview.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ const shouldSilentWebview = ConfigUtil.getConfigItem("silent", false);
2121
type WebViewProperties = {
2222
$root: Element;
2323
rootWebContents: WebContents;
24-
index: number;
2524
tabId: string;
2625
url: string;
2726
role: TabRole;
2827
isActive: () => boolean;
2928
switchLoading: (loading: boolean, url: string) => void;
30-
onNetworkError: (index: number) => void;
29+
onNetworkError: (id: string) => void;
3130
preload?: string;
3231
onTitleChange: () => void;
3332
hasPermission?: (origin: string, permission: string) => boolean;
@@ -278,7 +277,7 @@ export default class WebView {
278277
if (hasConnectivityError) {
279278
console.error("error", errorDescription);
280279
if (!this.properties.url.includes("network.html")) {
281-
this.properties.onNetworkError(this.properties.index);
280+
this.properties.onNetworkError(this.properties.tabId);
282281
}
283282
}
284283
});

app/renderer/js/main.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ export class ServerManagerView {
388388
webview: WebView.create({
389389
$root: this.$webviewsContainer,
390390
rootWebContents,
391-
index,
392391
tabId,
393392
url: server.url,
394393
role: "server",
@@ -410,8 +409,8 @@ export class ServerManagerView {
410409
this.loading.has((await tab.webview).properties.url),
411410
);
412411
},
413-
onNetworkError: async (index: number) => {
414-
await this.openNetworkTroubleshooting(index);
412+
onNetworkError: async (tabId: string) => {
413+
await this.openNetworkTroubleshooting(tabId);
415414
},
416415
onTitleChange: this.updateBadge.bind(this),
417416
preload: url.pathToFileURL(path.join(bundlePath, "preload.cjs")).href,
@@ -631,8 +630,8 @@ export class ServerManagerView {
631630
});
632631
}
633632

634-
async openNetworkTroubleshooting(index: number): Promise<void> {
635-
const tab = this.tabs[index];
633+
async openNetworkTroubleshooting(id: string): Promise<void> {
634+
const tab = this.getTabById(id);
636635
if (!(tab instanceof ServerTab)) return;
637636
const webview = await tab.webview;
638637
const reconnectUtil = new ReconnectUtil(webview);
@@ -730,7 +729,9 @@ export class ServerManagerView {
730729
return;
731730
}
732731

733-
delete this.tabs[tab.properties.index]; // eslint-disable-line @typescript-eslint/no-array-delete
732+
this.tabs = this.tabs.filter(
733+
(tabObject) => tabObject.properties.tabId !== tabId,
734+
);
734735
await tab.destroy();
735736
this.functionalTabs.delete(page);
736737

@@ -1084,9 +1085,9 @@ export class ServerManagerView {
10841085
ipcRenderer.on(
10851086
"update-realm-name",
10861087
(event, serverURL: string, realmName: string) => {
1087-
for (const [index, domain] of DomainUtil.getDomains().entries()) {
1088+
for (const domain of DomainUtil.getDomains()) {
10881089
if (domain.url === serverURL) {
1089-
const tab = this.tabs[index];
1090+
const tab = this.getTabById(domain.id);
10901091
if (tab instanceof ServerTab) tab.setLabel(realmName);
10911092
domain.alias = realmName;
10921093
DomainUtil.updateDomainById(domain.id, domain);
@@ -1104,10 +1105,10 @@ export class ServerManagerView {
11041105
"update-realm-icon",
11051106
async (event, serverURL: string, iconURL: string) => {
11061107
await Promise.all(
1107-
DomainUtil.getDomains().map(async (domain, index) => {
1108+
DomainUtil.getDomains().map(async (domain) => {
11081109
if (domain.url === serverURL) {
11091110
const localIconPath = await DomainUtil.saveServerIcon(iconURL);
1110-
const tab = this.tabs[index];
1111+
const tab = this.getTabById(domain.id);
11111112
if (tab instanceof ServerTab)
11121113
tab.setIcon(DomainUtil.iconAsUrl(localIconPath));
11131114
domain.icon = localIconPath;

0 commit comments

Comments
 (0)