Skip to content

Commit 461c7ba

Browse files
committed
domain: tabId is now server id.
1 parent 9207147 commit 461c7ba

File tree

9 files changed

+30
-25
lines changed

9 files changed

+30
-25
lines changed

app/common/typed-ipc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type MainMessage = {
1414
"realm-name-changed": (serverURL: string, realmName: string) => void;
1515
"reload-full-app": () => void;
1616
"save-last-tab": (index: number) => void;
17-
"switch-server-tab": (index: number) => void;
17+
"switch-server-tab": (id: string) => void;
1818
"toggle-app": () => void;
1919
"toggle-badge-option": (newValue: boolean) => void;
2020
"toggle-menubar": (showMenubar: boolean) => void;
@@ -63,7 +63,7 @@ export type RendererMessage = {
6363
"set-idle": () => void;
6464
"show-keyboard-shortcuts": () => void;
6565
"show-notification-settings": () => void;
66-
"switch-server-tab": (index: number) => void;
66+
"switch-server-tab": (id: string) => void;
6767
"tab-devtools": () => void;
6868
"toggle-autohide-menubar": (
6969
autoHideMenubar: boolean,

app/common/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ export type TabData = {
3030
page?: TabPage;
3131
label: string;
3232
index: number;
33+
id: string;
3334
};

app/main/menu.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ function getWindowSubmenu(
329329
checked: tab === activeTab,
330330
click(_item, focusedWindow) {
331331
if (focusedWindow) {
332-
sendAction("switch-server-tab", tab.index);
332+
sendAction("switch-server-tab", tab.id);
333333
}
334334
},
335335
type: "checkbox",
@@ -701,22 +701,22 @@ async function checkForUpdate(): Promise<void> {
701701
await appUpdater(true);
702702
}
703703

704-
function getNextServer(tabs: TabData[], activeTab: TabData): number {
704+
function getNextServer(tabs: TabData[], activeTab: TabData): string {
705705
let {index} = activeTab;
706706
do {
707707
index = (index + 1) % tabs.length;
708708
} while (tabs[index]?.role !== "server");
709709

710-
return index;
710+
return tabs[index].id;
711711
}
712712

713-
function getPreviousServer(tabs: TabData[], activeTab: TabData): number {
713+
function getPreviousServer(tabs: TabData[], activeTab: TabData): string {
714714
let {index} = activeTab;
715715
do {
716716
index = (index - 1 + tabs.length) % tabs.length;
717717
} while (tabs[index]?.role !== "server");
718718

719-
return index;
719+
return tabs[index].id;
720720
}
721721

722722
export function setMenu(properties: MenuProperties): void {

app/renderer/js/components/server-tab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export default class ServerTab extends Tab {
8484
const shownIndex = this.properties.index + 1;
8585

8686
// Array index == Shown index - 1
87-
ipcRenderer.send("switch-server-tab", shownIndex - 1);
87+
ipcRenderer.send("switch-server-tab", this.properties.tabId);
8888

8989
return process.platform === "darwin"
9090
? `⌘${shownIndex}`

app/renderer/js/components/tab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type TabProperties = {
88
$root: Element;
99
onClick: () => void;
1010
index: number;
11-
tabId: number;
11+
tabId: string;
1212
onHover?: () => void;
1313
onHoverOut?: () => void;
1414
materialIcon?: string;

app/renderer/js/components/webview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type WebViewProperties = {
2222
$root: Element;
2323
rootWebContents: WebContents;
2424
index: number;
25-
tabId: number;
25+
tabId: string;
2626
url: string;
2727
role: TabRole;
2828
isActive: () => boolean;

app/renderer/js/main.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export class ServerManagerView {
8686
activeTab?: ServerOrFunctionalTab;
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 = server.id;
379377
const tab: ServerTab = new ServerTab({
380378
role: "server",
381379
icon: DomainUtil.iconAsUrl(server.icon),
@@ -483,10 +481,8 @@ export class ServerManagerView {
483481
this.toggleDndButton(dnd);
484482
}
485483

486-
gettabId(): number {
487-
const currentIndex = this.tabId;
488-
this.tabId++;
489-
return currentIndex;
484+
generateTabId(): string {
485+
return DomainUtil.generateDomainId();
490486
}
491487

492488
async getCurrentActiveServer(): Promise<string> {
@@ -574,7 +570,7 @@ export class ServerManagerView {
574570
const index = this.tabs.length;
575571
this.functionalTabs.set(tabProperties.page, index);
576572

577-
const tabId = this.gettabId();
573+
const tabId = this.generateTabId();
578574
const $view = await tabProperties.makeView();
579575
this.$webviewsContainer.append($view);
580576

@@ -668,6 +664,7 @@ export class ServerManagerView {
668664
page: tab.properties.page,
669665
label: tab.properties.label,
670666
index: tab.properties.index,
667+
id: tab.properties.tabId,
671668
};
672669
}
673670

@@ -824,14 +821,18 @@ export class ServerManagerView {
824821
}
825822
}
826823

827-
async isLoggedIn(tabId: number): Promise<boolean> {
828-
const tab = this.tabs[tabId];
824+
async isLoggedIn(index: number): Promise<boolean> {
825+
const tab = this.tabs[index];
829826
if (!(tab instanceof ServerTab)) return false;
830827
const webview = await tab.webview;
831828
const url = webview.getWebContents().getURL();
832829
return !(url.endsWith("/login/") || webview.loading);
833830
}
834831

832+
getTabById(tabId: string): ServerOrFunctionalTab | undefined {
833+
return this.tabs.find((tab) => tab.properties.tabId === tabId);
834+
}
835+
835836
addContextMenu($serverImg: HTMLElement, index: number): void {
836837
$serverImg.addEventListener("contextmenu", async (event) => {
837838
event.preventDefault();
@@ -1018,8 +1019,9 @@ export class ServerManagerView {
10181019
ipcRenderer.send("reload-full-app");
10191020
});
10201021

1021-
ipcRenderer.on("switch-server-tab", async (event, index: number) => {
1022-
await this.activateLastTab(index);
1022+
ipcRenderer.on("switch-server-tab", async (event, tabId: string) => {
1023+
const tab = this.getTabById(tabId)!;
1024+
await this.activateLastTab(tab.properties.index);
10231025
});
10241026

10251027
ipcRenderer.on("open-org-tab", async () => {

app/renderer/js/pages/preference/connected-org-section.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export function initConnectedOrgSection({
5353
$root: $serverInfoContainer,
5454
server,
5555
index: i,
56+
id: server.id,
5657
onChange: reloadApp,
5758
});
5859
}

app/renderer/js/pages/preference/server-info-form.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type ServerInfoFormProperties = {
1212
$root: Element;
1313
server: ServerConfig;
1414
index: number;
15+
id: string;
1516
onChange: () => void;
1617
};
1718

@@ -70,14 +71,14 @@ export function initServerInfoForm(properties: ServerInfoFormProperties): void {
7071
});
7172

7273
$openServerButton.addEventListener("click", () => {
73-
ipcRenderer.send("forward-message", "switch-server-tab", properties.index);
74+
ipcRenderer.send("forward-message", "switch-server-tab", properties.id);
7475
});
7576

7677
$serverInfoAlias.addEventListener("click", () => {
77-
ipcRenderer.send("forward-message", "switch-server-tab", properties.index);
78+
ipcRenderer.send("forward-message", "switch-server-tab", properties.id);
7879
});
7980

8081
$serverIcon.addEventListener("click", () => {
81-
ipcRenderer.send("forward-message", "switch-server-tab", properties.index);
82+
ipcRenderer.send("forward-message", "switch-server-tab", properties.id);
8283
});
8384
}

0 commit comments

Comments
 (0)