Skip to content

Commit 032f951

Browse files
committed
renderer: Add async constructors for functional tabs.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent d1aa577 commit 032f951

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

app/renderer/js/main.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ export class ServerManagerView {
547547
async openFunctionalTab(tabProps: {
548548
name: string;
549549
materialIcon: string;
550-
makeView: () => Element;
550+
makeView: () => Promise<Element>;
551551
destroyView: () => void;
552552
}): Promise<void> {
553553
if (this.functionalTabs.has(tabProps.name)) {
@@ -559,7 +559,7 @@ export class ServerManagerView {
559559
this.functionalTabs.set(tabProps.name, index);
560560

561561
const tabIndex = this.getTabIndex();
562-
const $view = tabProps.makeView();
562+
const $view = await tabProps.makeView();
563563
this.$webviewsContainer.append($view);
564564

565565
this.tabs.push(
@@ -590,8 +590,8 @@ export class ServerManagerView {
590590
await this.openFunctionalTab({
591591
name: "Settings",
592592
materialIcon: "settings",
593-
makeView: () => {
594-
this.preferenceView = new PreferenceView();
593+
makeView: async () => {
594+
this.preferenceView = await PreferenceView.create();
595595
this.preferenceView.$view.classList.add("functional-view");
596596
return this.preferenceView.$view;
597597
},
@@ -609,8 +609,8 @@ export class ServerManagerView {
609609
await this.openFunctionalTab({
610610
name: "About",
611611
materialIcon: "sentiment_very_satisfied",
612-
makeView() {
613-
aboutView = new AboutView();
612+
async makeView() {
613+
aboutView = await AboutView.create();
614614
aboutView.$view.classList.add("functional-view");
615615
return aboutView.$view;
616616
},

app/renderer/js/pages/about.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import {app} from "@electron/remote";
33
import {html} from "../../../common/html.js";
44

55
export class AboutView {
6+
static async create(): Promise<AboutView> {
7+
return new AboutView();
8+
}
9+
610
readonly $view: HTMLElement;
711

8-
constructor() {
12+
private constructor() {
913
this.$view = document.createElement("div");
1014
const $shadow = this.$view.attachShadow({mode: "open"});
1115
$shadow.innerHTML = html`

app/renderer/js/pages/preference/preference.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ import {initServersSection} from "./servers-section.js";
1313
import {initShortcutsSection} from "./shortcuts-section.js";
1414

1515
export class PreferenceView {
16+
static async create(): Promise<PreferenceView> {
17+
return new PreferenceView();
18+
}
19+
1620
readonly $view: HTMLElement;
1721
private readonly $shadow: ShadowRoot;
1822
private readonly $settingsContainer: Element;
1923
private readonly nav: Nav;
2024
private navItem: NavItem = "General";
2125

22-
constructor() {
26+
private constructor() {
2327
this.$view = document.createElement("div");
2428
this.$shadow = this.$view.attachShadow({mode: "open"});
2529
this.$shadow.innerHTML = html`

0 commit comments

Comments
 (0)