karlicoss / open-in-editor

Script to jump into files in you text editor, from your web browser
MIT License
9 stars 4 forks source link

consider replacing with native-messaging-hosts? #4

Open koo5 opened 3 years ago

koo5 commented 3 years ago

the protocol seems well developed: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging

a "client" installs wiith a single command: https://github.com/andy-portmen/native-client/releases

and it works: https://add0n.com/open-in.html

The way this seems to work is, the "client installer" puts a file like this:

{
    "name": "com.add0n.node",
    "description": "Node Host for Native Messaging",
    "path": "/home/koom/.config/com.add0n.node/run.sh",
    "type": "stdio",
    "allowed_extensions": ["{b8fa78dd-dae1-4839-9d0e-ce5e213083ce}","{5610edea-88c1-4370.....
    }

into ~/.mozilla/native-messaging-hosts/com.add0n.node.json where the browser picks it up.

and /home/koom/.config/com.add0n.node/run.sh is your code (or andy-portmen's code) that runs whatever it's told to.

koo5 commented 3 years ago
koom@dev ~/Downloads/ch> ./install.sh 
/tmp/fnm_multishell_28582_1614021112428/bin/node
NodeJS status = 0
Installer is using your system NodeJS.

 -> Root directory is /home/koom/.config
 -> Creating a directory at /home/koom/.config/google-chrome/NativeMessagingHosts
 -> Chrome Browser is supported
 -> Creating a directory at /home/koom/.config/chromium/NativeMessagingHosts
 -> Chromium Browser is supported
 -> Creating a directory at /home/koom/.config/vivaldi/NativeMessagingHosts
 -> Vivaldi Browser is supported
 -> Creating a directory at /home/koom/.config/BraveSoftware/Brave-Browser/NativeMessagingHosts
 -> Brave Browser is supported
 -> Creating a directory at /home/koom/.config/microsoftedge/NativeMessagingHosts
 -> Microsoft Edge Browser is supported
 -> Creating a directory at /home/koom/.mozilla/native-messaging-hosts
 -> Firefox Browser is supported
 -> Creating a directory at /home/koom/.waterfox/native-messaging-hosts
 -> Waterfox Browser is supported
 -> Creating a directory at /home/koom/.tor-browser/app/Browser/TorBrowser/Data/Browser/.mozilla/native-messaging-hosts
 -> Tor Browser is supported
 -> Creating a directory at /home/koom/.thunderbird/native-messaging-hosts
 -> Thunderbird Email Client is supported
 -> Creating a directory at /home/koom/.config/com.add0n.node
 => Native Host is installed in /home/koom/.config/com.add0n.node

>>> host is ready <<<
karlicoss commented 3 years ago

Hmm? So what's the difference with mime handler? For some reason I was under the impression that it needs an always running backend or something. In fact I thought of using it for Promnesia (instead of rest API), but encountered a few anecdotes claiming it's not well documented and doesn't really work well.. Have you played with it, what are the main benefits?

koo5 commented 3 years ago

i see how it can give the impression that there has to be a local server running, but fwiw, it seems to just work simply by putting the script into the appropriate path.

comparison:

All in all, i'm not arguing for or against it at this point, just wanted to note the option for future.

karlicoss commented 3 years ago

Agree, all makes sense, thanks for the summary! Yeah also mime handler can be tedious... e.g. here I've gone some serious rabbithole trying to figure out something as simple as "why firefox isn't opening sqlite database link in sqlitebrowser"... Guess in some sense it's much easier to put an arbitrary command to be executed by a native message.