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;
|
onUpdatedRan: boolean;
|
||||||
onReplacedRan: boolean;
|
onReplacedRan: boolean;
|
||||||
loginToAutoFill: any = null;
|
loginToAutoFill: any = null;
|
||||||
|
lockedVaultPendingNotifications: { commandToRetry: any, from: string }[] = [];
|
||||||
|
|
||||||
private commandsBackground: CommandsBackground;
|
private commandsBackground: CommandsBackground;
|
||||||
private contextMenusBackground: ContextMenusBackground;
|
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) {
|
async logout(expired: boolean) {
|
||||||
await this.eventService.uploadEvents();
|
await this.eventService.uploadEvents();
|
||||||
const userId = await this.userService.getUserId();
|
const userId = await this.userService.getUserId();
|
||||||
|
|
|
@ -25,8 +25,6 @@ export default class RuntimeBackground {
|
||||||
private pageDetailsToAutoFill: any[] = [];
|
private pageDetailsToAutoFill: any[] = [];
|
||||||
private onInstalledReason: string = null;
|
private onInstalledReason: string = null;
|
||||||
|
|
||||||
private lockedVaultPendingNotifications: any[] = [];
|
|
||||||
|
|
||||||
constructor(private main: MainBackground, private autofillService: AutofillService,
|
constructor(private main: MainBackground, private autofillService: AutofillService,
|
||||||
private platformUtilsService: BrowserPlatformUtilsService,
|
private platformUtilsService: BrowserPlatformUtilsService,
|
||||||
private storageService: StorageService, private i18nService: I18nService,
|
private storageService: StorageService, private i18nService: I18nService,
|
||||||
|
@ -54,26 +52,31 @@ export default class RuntimeBackground {
|
||||||
switch (msg.command) {
|
switch (msg.command) {
|
||||||
case 'loggedIn':
|
case 'loggedIn':
|
||||||
case 'unlocked':
|
case 'unlocked':
|
||||||
if (this.lockedVaultPendingNotifications.length > 0) {
|
if (this.main.lockedVaultPendingNotifications.length > 0) {
|
||||||
await BrowserApi.closeLoginTab();
|
await BrowserApi.closeLoginTab();
|
||||||
|
|
||||||
if (item?.sender?.tab?.id) {
|
const item = this.main.lockedVaultPendingNotifications[0];
|
||||||
await BrowserApi.focusSpecifiedTab(item.sender.tab.id);
|
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.setIcon();
|
||||||
await this.main.refreshBadgeAndMenu(false);
|
await this.main.refreshBadgeAndMenu(false);
|
||||||
this.notificationsService.updateConnection(msg.command === 'unlocked');
|
this.notificationsService.updateConnection(msg.command === 'unlocked');
|
||||||
this.systemService.cancelProcessReload();
|
this.systemService.cancelProcessReload();
|
||||||
|
|
||||||
|
this.main.unlockCompleted();
|
||||||
break;
|
break;
|
||||||
case 'addToLockedVaultPendingNotifications':
|
case 'addToLockedVaultPendingNotifications':
|
||||||
const retryMessage = {
|
const retryMessage = {
|
||||||
msg: msg.retryItem,
|
commandToRetry: {
|
||||||
sender: sender,
|
...msg.retryItem,
|
||||||
|
sender: sender
|
||||||
|
},
|
||||||
|
from: msg.from,
|
||||||
};
|
};
|
||||||
this.lockedVaultPendingNotifications.push(retryMessage);
|
this.main.lockedVaultPendingNotifications.push(retryMessage);
|
||||||
break;
|
break;
|
||||||
case 'logout':
|
case 'logout':
|
||||||
await this.main.logout(msg.expired);
|
await this.main.logout(msg.expired);
|
||||||
|
|
|
@ -78,6 +78,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
|
||||||
sendPlatformMessage({
|
sendPlatformMessage({
|
||||||
command: 'addToLockedVaultPendingNotifications',
|
command: 'addToLockedVaultPendingNotifications',
|
||||||
|
from: 'notificationBar',
|
||||||
retryItem: bgAddSaveMessage
|
retryItem: bgAddSaveMessage
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
@ -122,6 +123,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
|
||||||
sendPlatformMessage({
|
sendPlatformMessage({
|
||||||
command: 'addToLockedVaultPendingNotifications',
|
command: 'addToLockedVaultPendingNotifications',
|
||||||
|
from: 'notificationBar',
|
||||||
retryItem: bgChangeSaveMessage,
|
retryItem: bgChangeSaveMessage,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue