From 75fbccb945a26b361d025851fd35a61829b3c4e8 Mon Sep 17 00:00:00 2001 From: Daniel James Smith Date: Fri, 27 Jan 2023 11:49:35 +0100 Subject: [PATCH] [PS-1137] Fix reseed storage (#4543) * Fix storage reseed on logout The check for the set vault-timeout needs to happen before all cleaning stateService Remove check inside of reseedStorage as happens outside prior to calling it (logout/settings.component) * Remove old limitation to only run on certain browsers Execute on all browsers besides Safari as it does not support chrome.storage.local.get with an empty key https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/StorageArea/get * Revert "Remove old limitation to only run on certain browsers" This reverts commit d7f71aa0b6ee20f7bc1145f8d06c7d2191587935. --- apps/browser/src/background/main.background.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index f281fe356dc..fcde4e7c15f 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -678,6 +678,9 @@ export default class MainBackground { this.vaultFilterService.clear(), ]); + //Needs to be checked before state is cleaned + const needStorageReseed = await this.needsStorageReseed(); + await this.stateService.clean({ userId: userId }); if (userId == null || userId === (await this.stateService.getUserId())) { @@ -685,17 +688,25 @@ export default class MainBackground { this.messagingService.send("doneLoggingOut", { expired: expired, userId: userId }); } + if (needStorageReseed) { + await this.reseedStorage(); + } + if (BrowserApi.manifestVersion === 3) { BrowserApi.sendMessage("updateBadge"); } await this.refreshBadge(); await this.mainContextMenuHandler.noAccess(); - await this.reseedStorage(); this.notificationsService.updateConnection(false); await this.systemService.clearPendingClipboard(); await this.systemService.startProcessReload(this.authService); } + private async needsStorageReseed(): Promise { + const currentVaultTimeout = await this.stateService.getVaultTimeout(); + return currentVaultTimeout == null ? false : true; + } + async collectPageDetailsForContentScript(tab: any, sender: string, frameId: number = null) { if (tab == null || !tab.id) { return; @@ -736,11 +747,6 @@ export default class MainBackground { return; } - const currentVaultTimeout = await this.stateService.getVaultTimeout(); - if (currentVaultTimeout == null) { - return; - } - const getStorage = (): Promise => new Promise((resolve) => { chrome.storage.local.get(null, (o: any) => resolve(o));