Feature: Add access keys/hotkeys/mnemonics for context menu
This is a reinstalment of the feature first introduced in #55, which was removed in #70.
It adds an access key (a.k.a. hotkey or mnemonic) to the context menu items created by ff2mpv.
An access key is an underlined (or otherwise highlighted) alphanumeric character in a menu item which activates that item on key press.
This is different from the extension shortcut which can be set by the user as a custom combination of keys that activates the extension action button.
Firefox will underline the specified access key for each item in context menus. Chromium does not underline the access keys, they remain hidden, albeit still functional.
Originally in #55, W was chosen as access key. This was later found to be in conflict with Firefox Multi-Account Containers addon (#64). As a temporary solution, V has been picked as access key on Windows (#65, #66). But the conflict is not limited to Windows. Furthermore, on Chromium, W is also taken by the "Open in new window" menu item for link context menus, which suggests revisiting our choice.
These are the keys that are available by default for all the contexts for Firefox and Chromium:
| link | image | video | audio | selection | frame | |
|---|---|---|---|---|---|---|
| Firefox | WERYUIO | WERUP | WERY | WERTYU | WYUOP | WETYUO |
| AFGHJ | ASDFHJKL | GHJK | SFGHJK | DFGHJKL | DFGJKL | |
| ZXCVM | ZXCBNM | ZXN | ZXCN | ZXVM | ZXCBN | |
| Chromium | QRYUIOP | QWERTUP | QWERTUI | QWERTYUIP | QWERTYUI | QWETYUI |
| ASDFHJL | ASDFGHJKL | ASDGHJK | ASDFGHJK | ADFGHJKL | SDGHJKL | |
| ZXCVBM | ZXBM | ZXBM | ZXBM | ZXBM | ZXVBM |
We can see that W is vacant for Firefox if Multi-Account Containers addon is not installed. This is also my preferred key as explained in #55.
However, we need to check if it's installed. To avoid using maintenance.get() and requiring another permission (as established in #64), we can try to send an external message to that addon. If this raises an exception saying the connection couldn't be established, it means the addon is not installed and we can safely apply W as access key. This approach can be used to detect possible conflicts with other extensions in future.
If the Multi-Account Containers addon is installed, or we are on Chromium, then we use X. It's not ideal, but it's either that or Z if we're going to use the same key for all browsers.
An alternative and simpler approach would be to just use X everywhere and not care for any conflicts.
Hi @Dimithrandir, thanks for the PR.
An alternative and simpler approach would be to just use X everywhere and not care for any conflicts.
I think I prefer this -- I don't love the idea of sending messages to other addons to sniff their presence. Doing so feels both brittle (it's arguably an information leak, so maybe browsers will fix the permissions hole here in the future) and more surprising/intrusive than having a single consistent key everywhere.
I have changed the key to X everywhere. I kept the strings as constants though, as one of them is accessed twice and they might potentially be used multiple times in future.
(it's arguably an information leak, so maybe browsers will fix the permissions hole here in the future)
I think this is by design. Extensions are supposed to communicate between each other and it's up to the each extension to control which external extension's messages it will receive. But I agree that it looks very clumsy.