1
0
mirror of https://github.com/bitwarden/browser synced 2025-01-04 14:22:50 +01:00

add fixes for keybaord shortcuts in safari

This commit is contained in:
Kyle Spearrin 2018-01-17 10:11:09 -05:00
parent 09ef4b08aa
commit f60414c872
4 changed files with 26 additions and 14 deletions

View File

@ -25,12 +25,11 @@ export default class CommandsBackground {
} }
if (this.isSafari) { if (this.isSafari) {
this.commands.addEventListener('message', async (msgEvent: any) => { BrowserApi.messageListener(async (msg: any, sender: any, sendResponse: any) => {
const msg = msgEvent.message; if (msg.command === 'keyboardShortcutTriggered' && msg.shortcut) {
if (msg.command === 'keyboardShortcutTriggered' && msg.command.shortcut) { await this.processCommand(msg.shortcut);
await this.processCommand(msg.command.shortcut);
} }
}, false); });
} else { } else {
this.commands.onCommand.addListener(async (command: any) => { this.commands.onCommand.addListener(async (command: any) => {
await this.processCommand(command); await this.processCommand(command);
@ -38,13 +37,13 @@ export default class CommandsBackground {
} }
} }
private async processCommand(command: string) { private async processCommand(command: string, sender?: any) {
switch (command) { switch (command) {
case 'generate_password': case 'generate_password':
await this.generatePasswordToClipboard(); await this.generatePasswordToClipboard();
break; break;
case 'autofill_login': case 'autofill_login':
await this.autoFillLogin(); await this.autoFillLogin(sender ? sender.tab : null);
break; break;
case 'open_popup': case 'open_popup':
await this.openPopup(); await this.openPopup();
@ -55,6 +54,11 @@ export default class CommandsBackground {
} }
private async generatePasswordToClipboard() { private async generatePasswordToClipboard() {
if (this.isSafari) {
// Safari does not support access to clipboard from background
return;
}
const options = await this.passwordGenerationService.getOptions(); const options = await this.passwordGenerationService.getOptions();
const password = await this.passwordGenerationService.generatePassword(options); const password = await this.passwordGenerationService.generatePassword(options);
UtilsService.copyToClipboard(password); UtilsService.copyToClipboard(password);
@ -66,8 +70,11 @@ export default class CommandsBackground {
}); });
} }
private async autoFillLogin() { private async autoFillLogin(tab?: any) {
const tab = await BrowserApi.getTabFromCurrentWindowId(); if (!tab) {
tab = await BrowserApi.getTabFromCurrentWindowId();
}
if (tab == null) { if (tab == null) {
return; return;
} }

View File

@ -19,7 +19,8 @@ document.addEventListener('DOMContentLoaded', (event) => {
arguments)}}(b))};c.init();r.Mousetrap=c;"undefined"!==typeof module&&module.exports&&(module.exports=c);"function"===typeof define&&define.amd&&define(function(){return c})}})("undefined"!==typeof window?window:null,"undefined"!==typeof window?document:null); arguments)}}(b))};c.init();r.Mousetrap=c;"undefined"!==typeof module&&module.exports&&(module.exports=c);"function"===typeof define&&define.amd&&define(function(){return c})}})("undefined"!==typeof window?window:null,"undefined"!==typeof window?document:null);
/* mousetrap v1.6.1 craig.is/killing/mice */ /* mousetrap v1.6.1 craig.is/killing/mice */
Mousetrap.bind('mod+shift+l', () => { const autofillCommand = isSafari ? 'mod+shift+l' : 'mod+shift+l';
Mousetrap.bind(autofillCommand, () => {
sendMessage('autofill_login'); sendMessage('autofill_login');
}); });
@ -27,9 +28,11 @@ document.addEventListener('DOMContentLoaded', (event) => {
sendMessage('open_popup'); sendMessage('open_popup');
}); });
Mousetrap.bind('mod+shift+9', () => { if (!isSafari) {
sendMessage('generate_password'); Mousetrap.bind('mod+shift+9', () => {
}); sendMessage('generate_password');
});
}
function sendMessage(shortcut) { function sendMessage(shortcut) {
if (isSafari) { if (isSafari) {
@ -38,7 +41,7 @@ document.addEventListener('DOMContentLoaded', (event) => {
shortcut: shortcut shortcut: shortcut
}); });
} else { } else {
// not supported at this time. // other browsers not supported at this time.
} }
} }
}); });

View File

@ -64,6 +64,7 @@
<string>content/autofill.js</string> <string>content/autofill.js</string>
<string>content/autofiller.js</string> <string>content/autofiller.js</string>
<string>content/notificationBar.js</string> <string>content/notificationBar.js</string>
<string>content/shortcuts.js</string>
</array> </array>
</dict> </dict>
<key>Stylesheets</key> <key>Stylesheets</key>

View File

@ -21,6 +21,7 @@ module.exports = {
'content/autofill': './src/content/autofill.js', 'content/autofill': './src/content/autofill.js',
'content/autofiller': './src/content/autofiller.js', 'content/autofiller': './src/content/autofiller.js',
'content/notificationBar': './src/content/notificationBar.js', 'content/notificationBar': './src/content/notificationBar.js',
'content/shortcuts': './src/content/shortcuts.js',
'notification/bar': './src/notification/bar.js', 'notification/bar': './src/notification/bar.js',
'downloader/downloader': './src/downloader/downloader.ts', 'downloader/downloader': './src/downloader/downloader.ts',
}, },