From 1746d27b5ec0a9540280b11b889123d9ff783c83 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Thu, 15 Apr 2021 11:17:28 -0700 Subject: [PATCH] Wait for `appView` to be there in `onEmpty` --- ts/background.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ts/background.ts b/ts/background.ts index 526f0f642652..b7f700d976ab 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -30,6 +30,11 @@ export async function startApp(): Promise { ); } + let resolveOnAppView: (() => void) | undefined; + const onAppView = new Promise(resolve => { + resolveOnAppView = resolve; + }); + window.textsecure.protobuf.onLoad(() => { window.storage.onready(() => { senderCertificateService.initialize({ @@ -1605,6 +1610,11 @@ export async function startApp(): Promise { await window.textsecure.messaging.sendRequestKeySyncMessage(); } ); + + if (resolveOnAppView) { + resolveOnAppView(); + resolveOnAppView = undefined; + } } window.getSyncRequest = (timeoutMillis?: number) => { @@ -2111,6 +2121,7 @@ export async function startApp(): Promise { window.Whisper.deliveryReceiptQueue.start(); window.Whisper.Notifications.enable(); + await onAppView; const view = window.owsDesktopApp.appView; if (!view) { throw new Error('Expected `appView` to be initialized');