add support for shortcuts to edge and vivaldi
This commit is contained in:
parent
51dffa79a1
commit
c942dd3410
|
@ -12,22 +12,26 @@ import { UtilsService } from 'jslib/services/utils.service';
|
||||||
export default class CommandsBackground {
|
export default class CommandsBackground {
|
||||||
private commands: any;
|
private commands: any;
|
||||||
private isSafari: boolean;
|
private isSafari: boolean;
|
||||||
|
private isEdge: boolean;
|
||||||
|
private isVivaldi: boolean;
|
||||||
|
|
||||||
constructor(private main: MainBackground, private passwordGenerationService: PasswordGenerationService,
|
constructor(private main: MainBackground, private passwordGenerationService: PasswordGenerationService,
|
||||||
private platformUtilsService: PlatformUtilsService) {
|
private platformUtilsService: PlatformUtilsService) {
|
||||||
this.isSafari = this.platformUtilsService.isSafari();
|
this.isSafari = this.platformUtilsService.isSafari();
|
||||||
|
this.isEdge = this.platformUtilsService.isEdge();
|
||||||
|
this.isVivaldi = this.platformUtilsService.isVivaldi();
|
||||||
this.commands = this.isSafari ? safari.application : chrome.commands;
|
this.commands = this.isSafari ? safari.application : chrome.commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
if (!this.commands) {
|
if (!this.commands && !this.isEdge) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isSafari) {
|
if (this.isSafari || this.isEdge || this.isVivaldi) {
|
||||||
BrowserApi.messageListener(async (msg: any, sender: any, sendResponse: any) => {
|
BrowserApi.messageListener(async (msg: any, sender: any, sendResponse: any) => {
|
||||||
if (msg.command === 'keyboardShortcutTriggered' && msg.shortcut) {
|
if (msg.command === 'keyboardShortcutTriggered' && msg.shortcut) {
|
||||||
await this.processCommand(msg.shortcut);
|
await this.processCommand(msg.shortcut, sender);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -54,7 +58,7 @@ export default class CommandsBackground {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async generatePasswordToClipboard() {
|
private async generatePasswordToClipboard() {
|
||||||
if (this.isSafari) {
|
if (this.isSafari || this.isEdge) {
|
||||||
// Safari does not support access to clipboard from background
|
// Safari does not support access to clipboard from background
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -88,6 +92,7 @@ export default class CommandsBackground {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async openPopup() {
|
private async openPopup() {
|
||||||
|
// Chrome APIs cannot open popup
|
||||||
if (!this.isSafari || !safari.extension.toolbarItems || !safari.extension.toolbarItems.length) {
|
if (!this.isSafari || !safari.extension.toolbarItems || !safari.extension.toolbarItems.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
document.addEventListener('DOMContentLoaded', (event) => {
|
document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
const isSafari = (typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 &&
|
const isSafari = (typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 &&
|
||||||
navigator.userAgent.indexOf('Chrome') === -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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,29 +25,31 @@ document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const autofillCommand = isSafari ? 'mod+\\' : 'mod+shift+l';
|
const autofillCommand = isSafari || isEdge ? 'mod+\\' : 'mod+shift+l';
|
||||||
Mousetrap.bind(autofillCommand, () => {
|
Mousetrap.bind(autofillCommand, () => {
|
||||||
sendMessage('autofill_login');
|
sendMessage('autofill_login');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (isSafari) {
|
||||||
Mousetrap.bind('mod+shift+y', () => {
|
Mousetrap.bind('mod+shift+y', () => {
|
||||||
sendMessage('open_popup');
|
sendMessage('open_popup');
|
||||||
});
|
});
|
||||||
|
} else if (!this.isEdge) {
|
||||||
if (!isSafari) {
|
|
||||||
Mousetrap.bind('mod+shift+9', () => {
|
Mousetrap.bind('mod+shift+9', () => {
|
||||||
sendMessage('generate_password');
|
sendMessage('generate_password');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendMessage(shortcut) {
|
function sendMessage(shortcut) {
|
||||||
if (isSafari) {
|
const msg = {
|
||||||
safari.self.tab.dispatchMessage('bitwarden', {
|
|
||||||
command: 'keyboardShortcutTriggered',
|
command: 'keyboardShortcutTriggered',
|
||||||
shortcut: shortcut
|
shortcut: shortcut
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (isSafari) {
|
||||||
|
safari.self.tab.dispatchMessage('bitwarden', msg);
|
||||||
} else {
|
} else {
|
||||||
// other browsers not supported at this time.
|
chrome.runtime.sendMessage(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,30 +18,8 @@
|
||||||
{
|
{
|
||||||
"all_frames": true,
|
"all_frames": true,
|
||||||
"js": [
|
"js": [
|
||||||
"content/autofill.js"
|
"content/autofill.js",
|
||||||
],
|
"content/autofiller.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/notificationBar.js"
|
"content/notificationBar.js"
|
||||||
],
|
],
|
||||||
"matches": [
|
"matches": [
|
||||||
|
@ -51,6 +29,18 @@
|
||||||
],
|
],
|
||||||
"run_at": "document_start"
|
"run_at": "document_start"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"all_frames": false,
|
||||||
|
"js": [
|
||||||
|
"content/shortcuts.js"
|
||||||
|
],
|
||||||
|
"matches": [
|
||||||
|
"http://*/*",
|
||||||
|
"https://*/*",
|
||||||
|
"file:///*"
|
||||||
|
],
|
||||||
|
"run_at": "document_start"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"all_frames": true,
|
"all_frames": true,
|
||||||
"css": [
|
"css": [
|
||||||
|
|
Loading…
Reference in New Issue