webview: Wait for dom-ready before sending messages.

Fixes tests/test-add-organization.js.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg
2020-03-02 18:36:52 -08:00
parent 675bc2f06c
commit 598b96b6e8
2 changed files with 9 additions and 4 deletions

View File

@@ -25,6 +25,7 @@ class WebView extends BaseComponent {
customCSS: string;
$webviewsContainer: DOMTokenList;
$el: Electron.WebviewTag;
domReady?: Promise<void>;
// This is required because in main.js we access WebView.method as
// webview[method].
@@ -56,6 +57,9 @@ class WebView extends BaseComponent {
init(): void {
this.$el = this.generateNodeFromTemplate(this.template()) as Electron.WebviewTag;
this.domReady = new Promise(resolve => {
this.$el.addEventListener('dom-ready', () => resolve(), true);
});
this.props.$root.append(this.$el);
this.registerListeners();
@@ -292,7 +296,8 @@ class WebView extends BaseComponent {
this.init();
}
send(channel: string, ...param: any[]): void {
async send(channel: string, ...param: any[]): Promise<void> {
await this.domReady;
this.$el.send(channel, ...param);
}
}

View File

@@ -306,7 +306,7 @@ class ServerManagerView {
dialog.showErrorBox(title, content);
if (DomainUtil.getDomains().length === 0) {
// no orgs present, stop showing loading gif
this.openSettings('AddServer');
await this.openSettings('AddServer');
}
}
}
@@ -554,14 +554,14 @@ class ServerManagerView {
this.activateTab(this.functionalTabs[tabProps.name]);
}
openSettings(nav = 'General'): void {
async openSettings(nav = 'General'): Promise<void> {
this.openFunctionalTab({
name: 'Settings',
materialIcon: 'settings',
url: `file://${rendererDirectory}/preference.html#${nav}`
});
this.$settingsButton.classList.add('active');
this.tabs[this.functionalTabs.Settings].webview.send('switch-settings-nav', nav);
await this.tabs[this.functionalTabs.Settings].webview.send('switch-settings-nav', nav);
}
openAbout(): void {