Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launching Electron app from a standard web browser

Tags:

electron

Clicking a mailto: link will open my default mail client. In a similar manner, I would like to launch an Electron app with my-app:. What is the best way to achieve this and gracefully fallback to a standard http link if the app isn't installed?

Furthermore, I would also like to be able to pass through some extra details my-app:foo/bar. How would this be intercepted inside of Electron when it launches?

I have read some docs on what I think might be relevant stuff: http://electron.atom.io/docs/v0.36.0/api/protocol/ however as a frontend dev there's some gaps in my understanding of how the overarching process works. Any help much appreciated!

like image 639
Merlin Mason Avatar asked Jan 04 '16 15:01

Merlin Mason


1 Answers

Electron has evolved quite a bit since this question was first posted.

You no longer have to dive quite as deep and can skip the Electron protocol API. Instead, use the app.setAsDefaultProtocolClient(protocol[, path, args]) interface and its siblings app.removeAsDefaultProtocolClient(protocol[, path, args]) and app.isDefaultProtocolClient(protocol[, path, args]).

These enable you to register a protocol identifier your-protocol:// and receive arguments:

The whole link, including protocol, will be passed to your application as a parameter. Electron API docs

like image 113
Jens Habegger Avatar answered Oct 28 '22 00:10

Jens Habegger