From 838bfe94547ec004246ff03ddb83574341ef0b77 Mon Sep 17 00:00:00 2001 From: Daniel James Smith Date: Thu, 30 Sep 2021 16:43:10 +0200 Subject: [PATCH] Wait for user to log in before trying to save credentials --- src/background/main.background.ts | 1 + src/background/runtime.background.ts | 40 +++++++++++++++------------- src/notification/bar.js | 12 +++++++++ 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/background/main.background.ts b/src/background/main.background.ts index 288ca3f729..1671946e11 100644 --- a/src/background/main.background.ts +++ b/src/background/main.background.ts @@ -127,6 +127,7 @@ export default class MainBackground { onReplacedRan: boolean; loginToAutoFill: any = null; notificationQueue: any[] = []; + retryQueue: any[] = []; private commandsBackground: CommandsBackground; private contextMenusBackground: ContextMenusBackground; diff --git a/src/background/runtime.background.ts b/src/background/runtime.background.ts index 733147eaa4..2722ccd303 100644 --- a/src/background/runtime.background.ts +++ b/src/background/runtime.background.ts @@ -71,6 +71,18 @@ export default class RuntimeBackground { await this.main.refreshBadgeAndMenu(false); this.notificationsService.updateConnection(msg.command === 'unlocked'); this.systemService.cancelProcessReload(); + + if (this.main.retryQueue.length > 0) { + const retryItem = this.main.retryQueue.pop(); + await this.processMessage(retryItem.msg, retryItem.sender, null); + } + break; + case 'addToRetryQueue': + const retryMessage = { + msg: msg.retryItem, + sender: sender, + }; + this.main.retryQueue.push(retryMessage); break; case 'logout': await this.main.logout(msg.expired); @@ -224,10 +236,6 @@ export default class RuntimeBackground { } private async saveAddLogin(tab: any, folderId: string) { - console.log('saveAddLogin triggered'); - if (await this.vaultTimeoutService.isLocked()) { - return; - } for (let i = this.main.notificationQueue.length - 1; i >= 0; i--) { const queueMessage = this.main.notificationQueue[i]; @@ -268,10 +276,6 @@ export default class RuntimeBackground { } private async saveChangePassword(tab: any) { - console.log('saveChangePassword triggered'); - if (await this.vaultTimeoutService.isLocked()) { - return; - } for (let i = this.main.notificationQueue.length - 1; i >= 0; i--) { const queueMessage = this.main.notificationQueue[i]; @@ -361,20 +365,20 @@ export default class RuntimeBackground { } private async pushAddLoginToQueue(loginDomain: string, loginInfo: any, tab: any, isVaultLocked: boolean = false) { - // remove any old messages for this tab - this.removeTabFromNotificationQueue(tab); + // remove any old messages for this tab + this.removeTabFromNotificationQueue(tab); const message: addLoginQueueMessage = { - type: 'addLogin', - username: loginInfo.username, - password: loginInfo.password, - domain: loginDomain, - uri: loginInfo.url, - tabId: tab.id, - expires: new Date((new Date()).getTime() + 30 * 60000), // 30 minutes + type: 'addLogin', + username: loginInfo.username, + password: loginInfo.password, + domain: loginDomain, + uri: loginInfo.url, + tabId: tab.id, + expires: new Date((new Date()).getTime() + 30 * 60000), // 30 minutes wasVaultLocked: isVaultLocked, }; this.main.notificationQueue.push(message); - await this.main.checkNotificationQueue(tab); + await this.main.checkNotificationQueue(tab); } private async changedPassword(changeData: any, tab: any) { diff --git a/src/notification/bar.js b/src/notification/bar.js index e26132b522..a010226907 100644 --- a/src/notification/bar.js +++ b/src/notification/bar.js @@ -73,6 +73,12 @@ document.addEventListener('DOMContentLoaded', () => { sendPlatformMessage({ command: 'openPopout' }); + + sendPlatformMessage({ + command: 'addToRetryQueue', + retryItem: bgAddSaveMessage + }); + return; } sendPlatformMessage(bgAddSaveMessage); @@ -111,6 +117,12 @@ document.addEventListener('DOMContentLoaded', () => { sendPlatformMessage({ command: 'openPopout' }); + + sendPlatformMessage({ + command: 'addToRetryQueue', + retryItem: bgChangeSaveMessage, + }); + return; } sendPlatformMessage(bgChangeSaveMessage); });