piroor / treestyletab

Tree Style Tab, Show tabs like a tree.
http://piro.sakura.ne.jp/xul/treestyletab/
Other
3.48k stars 279 forks source link

[Enhancement] API for other extension to toggle visibilty of sidebar #3588

Closed chaserhkj closed 3 months ago

chaserhkj commented 3 months ago

Abstract

I am trying to use Gesturefy to bind gestures onto TST actions. Since Gesturefy allows binding against external messages to other extensions, so far I've found much success in this integration with TST's external messaging APIs.

However, it seems that TST does not have an API for toggling the sidebar visibility. I tried to look for a Firefox-native solution of activating another extension, but it seems that no such solutions exist due to the strict separation of different extension sandboxes.

If I did miss out an existing solution of this problem from Gesturefy side, please do enlighten me.

Expected result

TST messaging API takes messages like { type: 'toggle-sidebar'} for toggling the visibility of TST sidebar.

piroor commented 3 months ago

It is impossible to provide such an API by an addon due to the restriction of WebExtensions API. The document sais:

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/sidebarAction/open

You can only call this function from inside the handler for a user action.

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/User_actions

To follow the principle of "no surprises", APIs like this can only be called from inside the handler for a user action. User actions include the following:

  • Clicking the extension's browser action or page action.
  • Selecting a context menu item defined by the extension.
  • Activating a keyboard shortcut defined by the extension (this only treated as a user action from Firefox 63 onwards).
  • Clicking a button in a page bundled with the extension.
chaserhkj commented 3 months ago

Thanks for the reply. That pretty much looks like a dead end for this issue.

I think on the Gesturefy side the handler for the gesture itself is definitely considered a user action. But if I understand it correctly as long as the call is passed through the messaging on the other end the user action flag is dropped. Ideally we probably want Firefox to preserve this flag across messaging since the message is sent from a user action handler, but that could be a tricky feature to push for since it may have very bad security implications.

For this issue itself, the workaround I am thinking is either to use Gesturefy to simulate key presses to activate TST, or just to bind TST activation shortcuts to the side keys on my mouse. But both of them will be out of the scope of TST so I am closing the issue now.