Skip to content

Commit 49039fe

Browse files
committed
tab: Use activeTab instead of activeTabIndex.
1 parent 54c924a commit 49039fe

File tree

6 files changed

+78
-73
lines changed

6 files changed

+78
-73
lines changed

app/common/config-schemata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const configSchemata = {
2121
downloadsPath: z.string(),
2222
enableSpellchecker: z.boolean(),
2323
errorReporting: z.boolean(),
24-
lastActiveTab: z.number(),
24+
lastActiveTabId: z.string().optional(),
2525
promptDownload: z.boolean(),
2626
proxyBypass: z.string(),
2727
// eslint-disable-next-line @typescript-eslint/naming-convention

app/common/typed-ipc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type MainMessage = {
1313
"realm-icon-changed": (serverURL: string, iconURL: string) => void;
1414
"realm-name-changed": (serverURL: string, realmName: string) => void;
1515
"reload-full-app": () => void;
16-
"save-last-tab": (index: number) => void;
16+
"save-last-tab": (id: string) => void;
1717
"switch-server-tab": (id: string) => void;
1818
"toggle-app": () => void;
1919
"toggle-badge-option": (newValue: boolean) => void;

app/common/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export type MenuProperties = {
22
tabs: TabData[];
3-
activeTabIndex?: number;
3+
activeTabId?: string;
44
enableMenu?: boolean;
55
};
66

app/main/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,11 @@ function createMainWindow(): BrowserWindow {
428428

429429
ipcMain.on("update-menu", (_event, properties: MenuProperties) => {
430430
AppMenu.setMenu(properties);
431-
if (properties.activeTabIndex !== undefined) {
432-
const activeTab = properties.tabs[properties.activeTabIndex];
433-
mainWindow.setTitle(`Zulip - ${activeTab.label}`);
431+
if (properties.activeTabId !== undefined) {
432+
const activeTab = properties.tabs.find(
433+
(tab) => tab.id === properties.activeTabId,
434+
);
435+
mainWindow.setTitle(`Zulip - ${activeTab!.label}`);
434436
}
435437
});
436438

@@ -452,8 +454,8 @@ function createMainWindow(): BrowserWindow {
452454
},
453455
);
454456

455-
ipcMain.on("save-last-tab", (_event, index: number) => {
456-
ConfigUtil.setConfigItem("lastActiveTab", index);
457+
ipcMain.on("save-last-tab", (_event, id: string) => {
458+
ConfigUtil.setConfigItem("lastActiveTabId", id);
457459
});
458460

459461
ipcMain.on("focus-this-webview", (event) => {

app/main/menu.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ function getHelpSubmenu(): MenuItemConstructorOptions[] {
294294

295295
function getWindowSubmenu(
296296
tabs: TabData[],
297-
activeTabIndex?: number,
297+
activeTabId?: string,
298298
): MenuItemConstructorOptions[] {
299299
const initialSubmenu: MenuItemConstructorOptions[] = [
300300
{
@@ -326,7 +326,7 @@ function getWindowSubmenu(
326326
label: tab.label,
327327
accelerator:
328328
tab.role === "function" ? "" : `${shortcutKey} + ${tab.index + 1}`,
329-
checked: tab.index === activeTabIndex,
329+
checked: tab.id === activeTabId,
330330
click(_item, focusedWindow) {
331331
if (focusedWindow) {
332332
sendAction("switch-server-tab", tab.id);
@@ -346,10 +346,7 @@ function getWindowSubmenu(
346346
enabled: tabs.length > 1,
347347
click(_item, focusedWindow) {
348348
if (focusedWindow) {
349-
sendAction(
350-
"switch-server-tab",
351-
getNextServer(tabs, activeTabIndex!),
352-
);
349+
sendAction("switch-server-tab", getNextServer(tabs, activeTabId!));
353350
}
354351
},
355352
},
@@ -361,7 +358,7 @@ function getWindowSubmenu(
361358
if (focusedWindow) {
362359
sendAction(
363360
"switch-server-tab",
364-
getPreviousServer(tabs, activeTabIndex!),
361+
getPreviousServer(tabs, activeTabId!),
365362
);
366363
}
367364
},
@@ -375,7 +372,7 @@ function getWindowSubmenu(
375372
function getDarwinTpl(
376373
properties: MenuProperties,
377374
): MenuItemConstructorOptions[] {
378-
const {tabs, activeTabIndex, enableMenu = false} = properties;
375+
const {tabs, activeTabId, enableMenu = false} = properties;
379376

380377
return [
381378
{
@@ -525,7 +522,7 @@ function getDarwinTpl(
525522
},
526523
{
527524
label: t.__("Window"),
528-
submenu: getWindowSubmenu(tabs, activeTabIndex),
525+
submenu: getWindowSubmenu(tabs, activeTabId),
529526
},
530527
{
531528
label: t.__("Tools"),
@@ -540,7 +537,7 @@ function getDarwinTpl(
540537
}
541538

542539
function getOtherTpl(properties: MenuProperties): MenuItemConstructorOptions[] {
543-
const {tabs, activeTabIndex, enableMenu = false} = properties;
540+
const {tabs, activeTabId, enableMenu = false} = properties;
544541
return [
545542
{
546543
label: t.__("File"),
@@ -673,7 +670,7 @@ function getOtherTpl(properties: MenuProperties): MenuItemConstructorOptions[] {
673670
},
674671
{
675672
label: t.__("Window"),
676-
submenu: getWindowSubmenu(tabs, activeTabIndex),
673+
submenu: getWindowSubmenu(tabs, activeTabId),
677674
},
678675
{
679676
label: t.__("Tools"),
@@ -704,7 +701,8 @@ async function checkForUpdate(): Promise<void> {
704701
await appUpdater(true);
705702
}
706703

707-
function getNextServer(tabs: TabData[], activeTab: TabData): string {
704+
function getNextServer(tabs: TabData[], activeTabId: string): string {
705+
const activeTab = tabs.find((tab) => tab.id === activeTabId)!;
708706
let {index} = activeTab;
709707
do {
710708
index = (index + 1) % tabs.length;
@@ -713,7 +711,8 @@ function getNextServer(tabs: TabData[], activeTab: TabData): string {
713711
return tabs[index].id;
714712
}
715713

716-
function getPreviousServer(tabs: TabData[], activeTab: TabData): string {
714+
function getPreviousServer(tabs: TabData[], activeTabId: string): string {
715+
const activeTab = tabs.find((tab) => tab.id === activeTabId)!;
717716
let {index} = activeTab;
718717
do {
719718
index = (index - 1 + tabs.length) % tabs.length;

0 commit comments

Comments
 (0)