1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-06-25 10:25:36 +02:00

add support for shortcuts to edge and vivaldi

This commit is contained in:
Kyle Spearrin 2018-01-17 13:38:32 -05:00
parent 51dffa79a1
commit c942dd3410
3 changed files with 39 additions and 40 deletions

View File

@ -12,22 +12,26 @@ import { UtilsService } from 'jslib/services/utils.service';
export default class CommandsBackground {
private commands: any;
private isSafari: boolean;
private isEdge: boolean;
private isVivaldi: boolean;
constructor(private main: MainBackground, private passwordGenerationService: PasswordGenerationService,
private platformUtilsService: PlatformUtilsService) {
this.isSafari = this.platformUtilsService.isSafari();
this.isEdge = this.platformUtilsService.isEdge();
this.isVivaldi = this.platformUtilsService.isVivaldi();
this.commands = this.isSafari ? safari.application : chrome.commands;
}
async init() {
if (!this.commands) {
if (!this.commands && !this.isEdge) {
return;
}
if (this.isSafari) {
if (this.isSafari || this.isEdge || this.isVivaldi) {
BrowserApi.messageListener(async (msg: any, sender: any, sendResponse: any) => {
if (msg.command === 'keyboardShortcutTriggered' && msg.shortcut) {
await this.processCommand(msg.shortcut);
await this.processCommand(msg.shortcut, sender);
}
});
} else {
@ -54,7 +58,7 @@ export default class CommandsBackground {
}
private async generatePasswordToClipboard() {
if (this.isSafari) {
if (this.isSafari || this.isEdge) {
// Safari does not support access to clipboard from background
return;
}
@ -88,6 +92,7 @@ export default class CommandsBackground {
}
private async openPopup() {
// Chrome APIs cannot open popup
if (!this.isSafari || !safari.extension.toolbarItems || !safari.extension.toolbarItems.length) {
return;
}

View File

@ -1,8 +1,10 @@
document.addEventListener('DOMContentLoaded', (event) => {
const isSafari = (typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 &&
navigator.userAgent.indexOf('Chrome') === -1;
const isEdge = !isSafari && navigator.userAgent.indexOf(' Edge/') !== -1;
const isVivaldi = !isSafari && navigator.userAgent.indexOf(' Vivaldi/') !== -1;
if (!isSafari) {
if (!isSafari && !isEdge && !isVivaldi) {
return;
}
@ -23,29 +25,31 @@ document.addEventListener('DOMContentLoaded', (event) => {
return false;
};
const autofillCommand = isSafari ? 'mod+\\' : 'mod+shift+l';
const autofillCommand = isSafari || isEdge ? 'mod+\\' : 'mod+shift+l';
Mousetrap.bind(autofillCommand, () => {
sendMessage('autofill_login');
});
Mousetrap.bind('mod+shift+y', () => {
sendMessage('open_popup');
});
if (!isSafari) {
if (isSafari) {
Mousetrap.bind('mod+shift+y', () => {
sendMessage('open_popup');
});
} else if (!this.isEdge) {
Mousetrap.bind('mod+shift+9', () => {
sendMessage('generate_password');
});
}
function sendMessage(shortcut) {
const msg = {
command: 'keyboardShortcutTriggered',
shortcut: shortcut
};
if (isSafari) {
safari.self.tab.dispatchMessage('bitwarden', {
command: 'keyboardShortcutTriggered',
shortcut: shortcut
});
safari.self.tab.dispatchMessage('bitwarden', msg);
} else {
// other browsers not supported at this time.
chrome.runtime.sendMessage(msg);
}
}
});

View File

@ -18,30 +18,8 @@
{
"all_frames": true,
"js": [
"content/autofill.js"
],
"matches": [
"http://*/*",
"https://*/*",
"file:///*"
],
"run_at": "document_start"
},
{
"all_frames": true,
"js": [
"content/autofiller.js"
],
"matches": [
"http://*/*",
"https://*/*",
"file:///*"
],
"run_at": "document_start"
},
{
"all_frames": true,
"js": [
"content/autofill.js",
"content/autofiller.js",
"content/notificationBar.js"
],
"matches": [
@ -51,6 +29,18 @@
],
"run_at": "document_start"
},
{
"all_frames": false,
"js": [
"content/shortcuts.js"
],
"matches": [
"http://*/*",
"https://*/*",
"file:///*"
],
"run_at": "document_start"
},
{
"all_frames": true,
"css": [