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) {
this.commands.addEventListener('message', async (msgEvent: any) => {
const msg = msgEvent.message;
if (msg.command === 'keyboardShortcutTriggered' && msg.command.shortcut) {
await this.processCommand(msg.command.shortcut);
BrowserApi.messageListener(async (msg: any, sender: any, sendResponse: any) => {
if (msg.command === 'keyboardShortcutTriggered' && msg.shortcut) {
await this.processCommand(msg.shortcut);
}
}, false);
});
} else {
this.commands.onCommand.addListener(async (command: any) => {
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) {
case 'generate_password':
await this.generatePasswordToClipboard();
break;
case 'autofill_login':
await this.autoFillLogin();
await this.autoFillLogin(sender ? sender.tab : null);
break;
case 'open_popup':
await this.openPopup();
@ -55,6 +54,11 @@ export default class CommandsBackground {
}
private async generatePasswordToClipboard() {
if (this.isSafari) {
// Safari does not support access to clipboard from background
return;
}
const options = await this.passwordGenerationService.getOptions();
const password = await this.passwordGenerationService.generatePassword(options);
UtilsService.copyToClipboard(password);
@ -66,8 +70,11 @@ export default class CommandsBackground {
});
}
private async autoFillLogin() {
const tab = await BrowserApi.getTabFromCurrentWindowId();
private async autoFillLogin(tab?: any) {
if (!tab) {
tab = await BrowserApi.getTabFromCurrentWindowId();
}
if (tab == null) {
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);
/* 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');
});
@ -27,9 +28,11 @@ document.addEventListener('DOMContentLoaded', (event) => {
sendMessage('open_popup');
});
Mousetrap.bind('mod+shift+9', () => {
sendMessage('generate_password');
});
if (!isSafari) {
Mousetrap.bind('mod+shift+9', () => {
sendMessage('generate_password');
});
}
function sendMessage(shortcut) {
if (isSafari) {
@ -38,7 +41,7 @@ document.addEventListener('DOMContentLoaded', (event) => {
shortcut: shortcut
});
} 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/autofiller.js</string>
<string>content/notificationBar.js</string>
<string>content/shortcuts.js</string>
</array>
</dict>
<key>Stylesheets</key>

View File

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