diff --git a/src/background/main.background.ts b/src/background/main.background.ts index e2ded7cbc07..0182b8f1b3e 100644 --- a/src/background/main.background.ts +++ b/src/background/main.background.ts @@ -127,6 +127,7 @@ export default class MainBackground { onUpdatedRan: boolean; onReplacedRan: boolean; loginToAutoFill: any = null; + lockedVaultPendingNotifications: { commandToRetry: any, from: string }[] = []; private commandsBackground: CommandsBackground; private contextMenusBackground: ContextMenusBackground; @@ -341,6 +342,21 @@ export default class MainBackground { } } + async unlockCompleted() { + if (this.lockedVaultPendingNotifications.length === 0) { + return; + } + + const lockedVaultPendingNotificationsItem = this.lockedVaultPendingNotifications.pop(); + switch (lockedVaultPendingNotificationsItem.from) { + case 'notificationBar': + await this.notificationBackground.processMessage(lockedVaultPendingNotificationsItem.commandToRetry, lockedVaultPendingNotificationsItem.commandToRetry.sender, null); + break; + default: + break; + } + } + async logout(expired: boolean) { await this.eventService.uploadEvents(); const userId = await this.userService.getUserId(); diff --git a/src/background/runtime.background.ts b/src/background/runtime.background.ts index 44919c9c74a..142f6d0973d 100644 --- a/src/background/runtime.background.ts +++ b/src/background/runtime.background.ts @@ -25,8 +25,6 @@ export default class RuntimeBackground { private pageDetailsToAutoFill: any[] = []; private onInstalledReason: string = null; - private lockedVaultPendingNotifications: any[] = []; - constructor(private main: MainBackground, private autofillService: AutofillService, private platformUtilsService: BrowserPlatformUtilsService, private storageService: StorageService, private i18nService: I18nService, @@ -54,26 +52,31 @@ export default class RuntimeBackground { switch (msg.command) { case 'loggedIn': case 'unlocked': - if (this.lockedVaultPendingNotifications.length > 0) { + if (this.main.lockedVaultPendingNotifications.length > 0) { await BrowserApi.closeLoginTab(); - if (item?.sender?.tab?.id) { - await BrowserApi.focusSpecifiedTab(item.sender.tab.id); + const item = this.main.lockedVaultPendingNotifications[0]; + if (item.commandToRetry?.sender?.tab?.id) { + await BrowserApi.focusSpecifiedTab(item.commandToRetry.sender.tab.id); } - await this.processMessage(item.msg, item.sender, null); } await this.main.setIcon(); await this.main.refreshBadgeAndMenu(false); this.notificationsService.updateConnection(msg.command === 'unlocked'); this.systemService.cancelProcessReload(); + + this.main.unlockCompleted(); break; case 'addToLockedVaultPendingNotifications': const retryMessage = { - msg: msg.retryItem, - sender: sender, + commandToRetry: { + ...msg.retryItem, + sender: sender + }, + from: msg.from, }; - this.lockedVaultPendingNotifications.push(retryMessage); + this.main.lockedVaultPendingNotifications.push(retryMessage); break; case 'logout': await this.main.logout(msg.expired); diff --git a/src/notification/bar.js b/src/notification/bar.js index 4cad508a057..d5590a31152 100644 --- a/src/notification/bar.js +++ b/src/notification/bar.js @@ -78,6 +78,7 @@ document.addEventListener('DOMContentLoaded', () => { sendPlatformMessage({ command: 'addToLockedVaultPendingNotifications', + from: 'notificationBar', retryItem: bgAddSaveMessage }); return; @@ -122,6 +123,7 @@ document.addEventListener('DOMContentLoaded', () => { sendPlatformMessage({ command: 'addToLockedVaultPendingNotifications', + from: 'notificationBar', retryItem: bgChangeSaveMessage, }); return;