Skip to content

Commit

Permalink
Support opening popover using keyboard shortcut
Browse files Browse the repository at this point in the history
Detect keyboard shortcut (ctrl + alt + a) in injected script and notify extension.
Extension gets access to toolbar item and shows it.
  • Loading branch information
kristofa committed Jul 6, 2019
1 parent 0bbfc45 commit f7d7ea3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Expand Up @@ -18,6 +18,14 @@ class SafariExtensionHandler: SFSafariExtensionHandler {
SafariExtensionViewController.shared.descriptionTextField.stringValue = ""
}
}
case "openPopover" :
page.getContainingTab { (tab) in
tab.getContainingWindow(completionHandler: { (window) in
window?.getToolbarItem(completionHandler: { (toolbaritem) in
toolbaritem?.showPopover()
})
})
}
default :
NSLog("Received unsupported message: \(messageName)")
}
Expand Down
6 changes: 6 additions & 0 deletions bookmarker for pinboard extension/script.js
Expand Up @@ -40,4 +40,10 @@ if (window.top === window) {
}
//console.log(selectedText);
});

document.addEventListener("keydown", function (keyDownEvent) {
if (keyDownEvent.ctrlKey && keyDownEvent.altKey && keyDownEvent.key === "a") {
safari.extension.dispatchMessage("openPopover");
}
});
}

0 comments on commit f7d7ea3

Please sign in to comment.