Move routing of actions after unlock into main.background
As we are unable to send a message from one background script to another, I moved the routing of the retryAction into main.background and call processMessages on the notificationBackground in unlockCompleted
This commit is contained in:
parent
9c0bfd28db
commit
ca0fe76172
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue