mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-11-02 13:03:22 +00:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user