diff --git a/src/background/notification.background.ts b/src/background/notification.background.ts index 58d2a04878..287f7437f6 100644 --- a/src/background/notification.background.ts +++ b/src/background/notification.background.ts @@ -23,6 +23,7 @@ import { PolicyType } from 'jslib-common/enums/policyType'; import AddChangePasswordQueueMessage from './models/addChangePasswordQueueMessage'; import AddLoginQueueMessage from './models/addLoginQueueMessage'; import { NotificationQueueMessageType } from './models/NotificationQueueMessageType'; +import lockedVaultPendingNotificationsItem from './models/lockedVaultPendingNotificationsItem'; export default class NotificationBackground { @@ -75,6 +76,18 @@ export default class NotificationBackground { break; case 'bgAddSave': case 'bgChangeSave': + if (await this.vaultTimeoutService.isLocked()) { + const retryMessage: lockedVaultPendingNotificationsItem = { + commandToRetry: { + msg: msg, + sender: sender, + }, + target: 'notification.background', + }; + await BrowserApi.tabSendMessageData(sender.tab, 'addToLockedVaultPendingNotifications', retryMessage); + await BrowserApi.tabSendMessageData(sender.tab, 'promptForLogin'); + return; + } await this.saveOrUpdateCredentials(sender.tab, msg.folder); break; case 'bgNeverSave': diff --git a/src/content/message_handler.ts b/src/content/message_handler.ts index 688553db7d..361e434fd7 100644 --- a/src/content/message_handler.ts +++ b/src/content/message_handler.ts @@ -22,6 +22,13 @@ window.addEventListener('message', event => { }, false); chrome.runtime.onMessage.addListener(event => { + if (event.command === 'promptForLogin') { + chrome.runtime.sendMessage(event); + } + + if (event.command === 'addToLockedVaultPendingNotifications') { + chrome.runtime.sendMessage(event); + } if (event.command === 'unlockCompleted') { chrome.runtime.sendMessage(event); diff --git a/src/notification/bar.js b/src/notification/bar.js index d5590a3115..fec7ed16f4 100644 --- a/src/notification/bar.js +++ b/src/notification/bar.js @@ -70,20 +70,6 @@ document.addEventListener('DOMContentLoaded', () => { command: 'bgAddSave', folder: folderId, }; - - if (isVaultLocked) { - sendPlatformMessage({ - command: 'promptForLogin' - }); - - sendPlatformMessage({ - command: 'addToLockedVaultPendingNotifications', - from: 'notificationBar', - retryItem: bgAddSaveMessage - }); - return; - } - sendPlatformMessage(bgAddSaveMessage); }); @@ -115,19 +101,6 @@ document.addEventListener('DOMContentLoaded', () => { const bgChangeSaveMessage = { command: 'bgChangeSave' }; - - if (isVaultLocked) { - sendPlatformMessage({ - command: 'promptForLogin' - }); - - sendPlatformMessage({ - command: 'addToLockedVaultPendingNotifications', - from: 'notificationBar', - retryItem: bgChangeSaveMessage, - }); - return; - } sendPlatformMessage(bgChangeSaveMessage); }); }