I currently implement a Safari App Extension, which I want to have the ability to show the extension's popover using a keyboard shortcut.
Using the old Safari Extension API, this was done by using
safari.extension.toolbarItem[0].showPopover()
in the inserted JavaScript. This, however, is not possible anymore in the new Safari App Extension API.
What I'm currently doing is to listen to a shortcut in the injected JavaScript and dispatch a message to the extension:
document.onkeyup = function(e) {
if (e.shiftKey && e.altKey && e.which == 80) {
safari.extension.dispatchMessage("showPopover");
}
};
In the extension, I have a message listener, which should load the popover:
override func messageReceived(withName messageName: String, from page:
SFSafariPage, userInfo: [String : Any]? = nil) {
page.getPropertiesWithCompletionHandler { properties in
if messageName == "showPopover" {
// Here the popover should be loaded...
}
}
}
I can not figure out how to do this. The Apple documentation does not provide any information. Stackoverflow and Github also did not help. I found, however, the following two questions on Stackoverflow, which seem to try to do a similar thing, but with no luck: [1], [2]
Any help on this? Is it just not possible? Or am I missing something?
Thank you for your help.