From c245c6932cdfe60b480be0cd0f33790f8f4ae78b Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 16 Mar 2020 19:00:13 +0000 Subject: [PATCH] Restore key backup in background after complete security We were blocking the complete security flow on waiting for a key backup restore to complete, which could take multiple minutes with no visible progress. Fixes https://github.com/vector-im/riot-web/issues/12426 --- .../structures/auth/CompleteSecurity.js | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/components/structures/auth/CompleteSecurity.js b/src/components/structures/auth/CompleteSecurity.js index 2e95f668a6..70732f4d9a 100644 --- a/src/components/structures/auth/CompleteSecurity.js +++ b/src/components/structures/auth/CompleteSecurity.js @@ -63,9 +63,30 @@ export default class CompleteSecurity extends React.Component { const backupInfo = await cli.getKeyBackupVersion(); this.setState({backupInfo}); - await accessSecretStorage(async () => { - await cli.checkOwnCrossSigningTrust(); - if (backupInfo) await cli.restoreKeyBackupWithSecretStorage(backupInfo); + // The control flow is fairly twisted here... + // For the purposes of completing security, we only wait on getting + // as far as the trust check and then show a green shield. + // We also begin the key backup restore as well, which we're + // awaiting inside `accessSecretStorage` only so that it keeps your + // passphase cached for that work. This dialog itself will only wait + // on the first trust check, and the key backup restore will happen + // in the background. + await new Promise((resolve, reject) => { + try { + accessSecretStorage(async () => { + await cli.checkOwnCrossSigningTrust(); + resolve(); + if (backupInfo) { + // A complete restore can take many minutes for large + // accounts / slow servers, so we allow the dialog + // to advance before this. + await cli.restoreKeyBackupWithSecretStorage(backupInfo); + } + }); + } catch (e) { + console.error(e); + reject(e); + } }); if (cli.getCrossSigningId()) {