Skip to content

Commit 467e7b1

Browse files
committed
functional-tab: Split ‘name’ into ‘page’ and ‘label’.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 105e7e9 commit 467e7b1

File tree

7 files changed

+39
-28
lines changed

7 files changed

+39
-28
lines changed

app/common/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ export type ServerConfig = {
2020
};
2121

2222
export type TabRole = "server" | "function";
23+
export type TabPage = "Settings" | "About";
2324

2425
export type TabData = {
2526
role: TabRole;
26-
name: string;
27+
page?: TabPage;
28+
label: string;
2729
index: number;
2830
};

app/main/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ ${error}`,
428428
AppMenu.setMenu(properties);
429429
if (properties.activeTabIndex !== undefined) {
430430
const activeTab = properties.tabs[properties.activeTabIndex];
431-
mainWindow.setTitle(`Zulip - ${activeTab.name}`);
431+
mainWindow.setTitle(`Zulip - ${activeTab.label}`);
432432
}
433433
});
434434

app/main/menu.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,12 @@ function getWindowSubmenu(
318318
if (tab === undefined) continue;
319319

320320
// Do not add functional tab settings to list of windows in menu bar
321-
if (tab.role === "function" && tab.name === "Settings") {
321+
if (tab.role === "function" && tab.page === "Settings") {
322322
continue;
323323
}
324324

325325
initialSubmenu.push({
326-
label: tab.name,
326+
label: tab.label,
327327
accelerator:
328328
tab.role === "function" ? "" : `${shortcutKey} + ${tab.index + 1}`,
329329
checked: tab.index === activeTabIndex,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {type Html, html} from "../../../common/html.js";
2+
import type {TabPage} from "../../../common/types.js";
23

34
import {generateNodeFromHtml} from "./base.js";
45
import Tab, {type TabProperties} from "./tab.js";
56

67
export type FunctionalTabProperties = {
78
$view: Element;
9+
page: TabPage;
810
} & TabProperties;
911

1012
export default class FunctionalTab extends Tab {
@@ -17,7 +19,7 @@ export default class FunctionalTab extends Tab {
1719

1820
this.$view = $view;
1921
this.$el = generateNodeFromHtml(this.templateHtml());
20-
if (this.properties.name !== "Settings") {
22+
if (properties.page !== "Settings") {
2123
this.properties.$root.append(this.$el);
2224
this.$closeButton = this.$el.querySelector(".server-tab-badge")!;
2325
this.registerListeners();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default class ServerTab extends Tab {
4949
return html`
5050
<div class="tab" data-tab-id="${this.properties.tabIndex}">
5151
<div class="server-tooltip" style="display:none">
52-
${this.properties.name}
52+
${this.properties.label}
5353
</div>
5454
<div class="server-tab-badge"></div>
5555
<div class="server-tab">
@@ -60,9 +60,9 @@ export default class ServerTab extends Tab {
6060
`;
6161
}
6262

63-
setName(name: string): void {
64-
this.properties.name = name;
65-
this.$name.textContent = name;
63+
setLabel(label: string): void {
64+
this.properties.label = label;
65+
this.$name.textContent = label;
6666
}
6767

6868
setIcon(icon: string): void {

app/renderer/js/components/tab.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import type {TabRole} from "../../../common/types.js";
1+
import type {TabPage, TabRole} from "../../../common/types.js";
22

33
export type TabProperties = {
44
role: TabRole;
5+
page?: TabPage;
56
icon?: string;
6-
name: string;
7+
label: string;
78
$root: Element;
89
onClick: () => void;
910
index: number;

app/renderer/js/main.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type {
2020
NavigationItem,
2121
ServerConfig,
2222
TabData,
23+
TabPage,
2324
} from "../../common/types.js";
2425
import defaultIcon from "../img/icon.png";
2526

@@ -81,7 +82,7 @@ export class ServerManagerView {
8182
loading: Set<string>;
8283
activeTabIndex: number;
8384
tabs: ServerOrFunctionalTab[];
84-
functionalTabs: Map<string, number>;
85+
functionalTabs: Map<TabPage, number>;
8586
tabIndex: number;
8687
presetOrgs: string[];
8788
preferenceView?: PreferenceView;
@@ -333,7 +334,7 @@ export class ServerManagerView {
333334
server.url,
334335
i,
335336
);
336-
tab.setName(serverConfig.alias);
337+
tab.setLabel(serverConfig.alias);
337338
tab.setIcon(DomainUtil.iconAsUrl(serverConfig.icon));
338339
(await tab.webview).setUnsupportedMessage(
339340
DomainUtil.getUnsupportedMessage(serverConfig),
@@ -376,7 +377,7 @@ export class ServerManagerView {
376377
const tab = new ServerTab({
377378
role: "server",
378379
icon: DomainUtil.iconAsUrl(server.icon),
379-
name: server.alias,
380+
label: server.alias,
380381
$root: this.$tabsContainer,
381382
onClick: this.activateLastTab.bind(this, index),
382383
index,
@@ -558,18 +559,19 @@ export class ServerManagerView {
558559
}
559560

560561
async openFunctionalTab(tabProperties: {
561-
name: string;
562+
label: string;
563+
page: TabPage;
562564
materialIcon: string;
563565
makeView: () => Promise<Element>;
564566
destroyView: () => void;
565567
}): Promise<void> {
566-
if (this.functionalTabs.has(tabProperties.name)) {
567-
await this.activateTab(this.functionalTabs.get(tabProperties.name)!);
568+
if (this.functionalTabs.has(tabProperties.page)) {
569+
await this.activateTab(this.functionalTabs.get(tabProperties.page)!);
568570
return;
569571
}
570572

571573
const index = this.tabs.length;
572-
this.functionalTabs.set(tabProperties.name, index);
574+
this.functionalTabs.set(tabProperties.page, index);
573575

574576
const tabIndex = this.getTabIndex();
575577
const $view = await tabProperties.makeView();
@@ -579,13 +581,14 @@ export class ServerManagerView {
579581
new FunctionalTab({
580582
role: "function",
581583
materialIcon: tabProperties.materialIcon,
582-
name: tabProperties.name,
584+
label: tabProperties.label,
585+
page: tabProperties.page,
583586
$root: this.$tabsContainer,
584587
index,
585588
tabIndex,
586589
onClick: this.activateTab.bind(this, index),
587590
onDestroy: async () => {
588-
await this.destroyTab(tabProperties.name, index);
591+
await this.destroyFunctionalTab(tabProperties.page, index);
589592
tabProperties.destroyView();
590593
},
591594
$view,
@@ -596,14 +599,15 @@ export class ServerManagerView {
596599
// closed when the functional tab DOM is ready, handled in webview.js
597600
this.$webviewsContainer.classList.remove("loaded");
598601

599-
await this.activateTab(this.functionalTabs.get(tabProperties.name)!);
602+
await this.activateTab(this.functionalTabs.get(tabProperties.page)!);
600603
}
601604

602605
async openSettings(
603606
navigationItem: NavigationItem = "General",
604607
): Promise<void> {
605608
await this.openFunctionalTab({
606-
name: "Settings",
609+
page: "Settings",
610+
label: "Settings",
607611
materialIcon: "settings",
608612
makeView: async () => {
609613
this.preferenceView = await PreferenceView.create();
@@ -622,7 +626,8 @@ export class ServerManagerView {
622626
async openAbout(): Promise<void> {
623627
let aboutView: AboutView;
624628
await this.openFunctionalTab({
625-
name: "About",
629+
page: "About",
630+
label: "About",
626631
materialIcon: "sentiment_very_satisfied",
627632
async makeView() {
628633
aboutView = await AboutView.create();
@@ -660,7 +665,8 @@ export class ServerManagerView {
660665
get tabsForIpc(): TabData[] {
661666
return this.tabs.map((tab) => ({
662667
role: tab.properties.role,
663-
name: tab.properties.name,
668+
page: tab.properties.page,
669+
label: tab.properties.label,
664670
index: tab.properties.index,
665671
}));
666672
}
@@ -680,7 +686,7 @@ export class ServerManagerView {
680686
// If old tab is functional tab Settings, remove focus from the settings icon at sidebar bottom
681687
if (
682688
this.tabs[this.activeTabIndex].properties.role === "function" &&
683-
this.tabs[this.activeTabIndex].properties.name === "Settings"
689+
this.tabs[this.activeTabIndex].properties.page === "Settings"
684690
) {
685691
this.$settingsButton.classList.remove("active");
686692
}
@@ -722,7 +728,7 @@ export class ServerManagerView {
722728
this.$loadingIndicator.classList.toggle("hidden", !loading);
723729
}
724730

725-
async destroyTab(name: string, index: number): Promise<void> {
731+
async destroyFunctionalTab(page: TabPage, index: number): Promise<void> {
726732
const tab = this.tabs[index];
727733
if (tab instanceof ServerTab && (await tab.webview).loading) {
728734
return;
@@ -731,7 +737,7 @@ export class ServerManagerView {
731737
await tab.destroy();
732738

733739
delete this.tabs[index]; // eslint-disable-line @typescript-eslint/no-array-delete
734-
this.functionalTabs.delete(name);
740+
this.functionalTabs.delete(page);
735741

736742
// Issue #188: If the functional tab was not focused, do not activate another tab.
737743
if (this.activeTabIndex === index) {
@@ -1053,7 +1059,7 @@ export class ServerManagerView {
10531059
for (const [index, domain] of DomainUtil.getDomains().entries()) {
10541060
if (domain.url === serverURL) {
10551061
const tab = this.tabs[index];
1056-
if (tab instanceof ServerTab) tab.setName(realmName);
1062+
if (tab instanceof ServerTab) tab.setLabel(realmName);
10571063
domain.alias = realmName;
10581064
DomainUtil.updateDomain(index, domain);
10591065
// Update the realm name also on the Window menu

0 commit comments

Comments
 (0)