Use messages/events instead of main.unlockCompleted

This commit is contained in:
Daniel James Smith 2021-10-18 16:41:42 +02:00
parent 2699e0f5a0
commit fd8de4ca0c
No known key found for this signature in database
GPG Key ID: 03E4BD365FF06726
5 changed files with 33 additions and 29 deletions

View File

@ -129,16 +129,15 @@ export default class MainBackground {
onUpdatedRan: boolean;
onReplacedRan: boolean;
loginToAutoFill: CipherView = null;
lockedVaultPendingNotifications: { commandToRetry: any, from: string }[] = [];
private commandsBackground: CommandsBackground;
private contextMenusBackground: ContextMenusBackground;
private idleBackground: IdleBackground;
private notificationBackground: NotificationBackground;
private runtimeBackground: RuntimeBackground;
private tabsBackground: TabsBackground;
private webRequestBackground: WebRequestBackground;
private windowsBackground: WindowsBackground;
private notificationBackground: NotificationBackground;
private sidebarAction: any;
private buildingContextMenu: boolean;
@ -344,21 +343,6 @@ export default class MainBackground {
}
}
async unlockCompleted() {
if (this.lockedVaultPendingNotifications.length === 0) {
return;
}
const item = this.lockedVaultPendingNotifications.pop();
switch (item.from) {
case 'notificationBar':
await this.notificationBackground.processMessage(item.commandToRetry, item.commandToRetry.sender, null);
break;
default:
break;
}
}
async logout(expired: boolean) {
await this.eventService.uploadEvents();
const userId = await this.userService.getUserId();

View File

@ -0,0 +1,7 @@
export default class lockedVaultPendingNotificationsItem {
commandToRetry: {
msg: any;
sender: chrome.runtime.MessageSender;
}
target: string;
}

View File

@ -48,6 +48,12 @@ export default class NotificationBackground {
async processMessage(msg: any, sender: chrome.runtime.MessageSender) {
switch (msg.command) {
case 'unlockCompleted':
if (msg.data.target !== 'notification.background') {
return;
}
await this.processMessage(msg.data.commandToRetry.msg, msg.data.commandToRetry.sender);
break;
case 'bgGetDataForTab':
await this.getDataForTab(sender.tab, msg.responseCommand);
break;

View File

@ -13,10 +13,13 @@ import { BrowserApi } from '../browser/browserApi';
import MainBackground from './main.background';
import { Utils } from 'jslib-common/misc/utils';
import lockedVaultPendingNotificationsItem from './models/lockedVaultPendingNotificationsItem';
export default class RuntimeBackground {
private autofillTimeout: any;
private pageDetailsToAutoFill: any[] = [];
private onInstalledReason: string = null;
private lockedVaultPendingNotifications: lockedVaultPendingNotificationsItem[] = [];
constructor(private main: MainBackground, private autofillService: AutofillService,
private platformUtilsService: BrowserPlatformUtilsService,
@ -45,11 +48,13 @@ export default class RuntimeBackground {
switch (msg.command) {
case 'loggedIn':
case 'unlocked':
if (this.main.lockedVaultPendingNotifications.length > 0) {
let item: lockedVaultPendingNotificationsItem;
if (this.lockedVaultPendingNotifications.length > 0) {
await BrowserApi.closeLoginTab();
const item = this.main.lockedVaultPendingNotifications[0];
if (item.commandToRetry?.sender?.tab?.id) {
item = this.lockedVaultPendingNotifications.pop();
if (item.commandToRetry.sender?.tab?.id) {
await BrowserApi.focusSpecifiedTab(item.commandToRetry.sender.tab.id);
}
}
@ -59,17 +64,12 @@ export default class RuntimeBackground {
this.notificationsService.updateConnection(msg.command === 'unlocked');
this.systemService.cancelProcessReload();
this.main.unlockCompleted();
if (item) {
await BrowserApi.tabSendMessageData(item.commandToRetry.sender.tab, 'unlockCompleted', item);
}
break;
case 'addToLockedVaultPendingNotifications':
const retryMessage = {
commandToRetry: {
...msg.retryItem,
sender: sender,
},
from: msg.from,
};
this.main.lockedVaultPendingNotifications.push(retryMessage);
this.lockedVaultPendingNotifications.push(msg.data);
break;
case 'logout':
await this.main.logout(msg.expired);

View File

@ -20,3 +20,10 @@ window.addEventListener('message', event => {
});
}
}, false);
chrome.runtime.onMessage.addListener(event => {
if (event.command === 'unlockCompleted') {
chrome.runtime.sendMessage(event);
}
});