1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-29 17:38:04 +01:00

Enable unlock on autofill via keyboard shortcut

This commit is contained in:
Daniel James Smith 2021-10-19 15:55:36 +02:00
parent 86e3b9e423
commit c793552dfd
No known key found for this signature in database
GPG Key ID: 03E4BD365FF06726

View File

@ -5,6 +5,7 @@ import MainBackground from './main.background';
import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
import LockedVaultPendingNotificationsItem from './models/lockedVaultPendingNotificationsItem';
export default class CommandsBackground {
private isSafari: boolean;
@ -17,13 +18,17 @@ export default class CommandsBackground {
}
async init() {
if (this.isVivaldi) {
BrowserApi.messageListener('commands.background', async (msg: any, sender: chrome.runtime.MessageSender, sendResponse: any) => {
if (msg.command === 'keyboardShortcutTriggered' && msg.shortcut) {
if (msg.command === 'unlockCompleted' && msg.data.target === 'commands.background') {
await this.processCommand(msg.data.commandToRetry.msg.command, msg.data.commandToRetry.sender);
}
if (this.isVivaldi && msg.command === 'keyboardShortcutTriggered' && msg.shortcut) {
await this.processCommand(msg.shortcut, sender);
}
});
} else if (chrome && chrome.commands) {
if (!this.isVivaldi && chrome && chrome.commands) {
chrome.commands.onCommand.addListener(async (command: string) => {
await this.processCommand(command);
});
@ -57,10 +62,6 @@ export default class CommandsBackground {
}
private async autoFillLogin(tab?: chrome.tabs.Tab) {
if (await this.vaultTimeoutService.isLocked()) {
return;
}
if (!tab) {
tab = await BrowserApi.getTabFromCurrentWindowId();
}
@ -69,6 +70,20 @@ export default class CommandsBackground {
return;
}
if (await this.vaultTimeoutService.isLocked()) {
const retryMessage: LockedVaultPendingNotificationsItem = {
commandToRetry: {
msg: { command: 'autofill_login' },
sender: { tab: tab },
},
target: 'commands.background',
};
await BrowserApi.tabSendMessageData(tab, 'addToLockedVaultPendingNotifications', retryMessage);
BrowserApi.tabSendMessageData(tab, 'promptForLogin');
return;
}
await this.main.collectPageDetailsForContentScript(tab, 'autofill_cmd');
}