Repository navigation
Enable Electron to set/unset itself as default protocol handler (OS X, Windows) - #4896
Conversation
f93dfb0 to
da88b7d
Compare
|
|
||
| Clears the recent documents list. | ||
|
|
||
| ### `app.setAsDefaultProtocolClient(protocol)` _OS X_ _Windows_ |
There was a problem hiding this comment.
How will people unregister from this?
There was a problem hiding this comment.
On both systems, a different app can always overwrite. On OS X, simply removing would involve a bit of hackery (we could call the set with an invalid bundle is); on Windows, we could also delete or overwrite the key. Basically the same it works with magnet links, phone links, or other non-restricted uri schemes.
Both systems don't really have a way to simply "unset" custom uri schemes (in a way that would restore previous handlers, for instance), so I'm inclined to not offer an API that makes Electron users think that we can really offer that reliably.
I trust your opinion though, I could easily implement an "overwrite with nonsense" API.
There was a problem hiding this comment.
I'm mostly thinking about the uninstall case - on Mac people will delete the app and launchd will react appropriately, but on Windows you leave a trash regkey around. I'm not so worried about restoring whatever was there
There was a problem hiding this comment.
On the other side, if you check your registry right now, you'll see that we (Microsoft) leave all uri schemes that we ever came across there. We really like to collect them ;-)
Buuuut for a @paulcbetts 👍, I'd totally throw in a removeAsDefaultProtocolHandler, that checks if the current executable is set as handler for a given protocol and removes it. Thoughts?
This PR adds an API enabling Electron to set itself as the default protocol handler for a custom porotocl on both oS X and Windows. For details, please see `docs/app.md`. Closes electron#4857
da88b7d to
d2567b0
Compare
|
wouldn't |
| if (FAILED(commandKey.WriteValue(L"", exe.c_str()))) | ||
| return false; | ||
|
|
||
| VLOG(1) << "Chrome registered as default handler for " << protocol << "."; |
There was a problem hiding this comment.
log can be removed, or should be modified with applications' name.
There was a problem hiding this comment.
Good catch, thanks!
ad48c66 to
40356dd
Compare
|
Added a Oh, and @deepak1556: I don't think so, given that other APIs that are similar also live in browser.cc - see Dock interactions or executable operations. I think this API should really be neighbors with AddRecentDocuments, SetAppUserModelID, etc. |
Yup but the browser class says |
| .SetMethod("setUserTasks", | ||
| base::Bind(&Browser::SetUserTasks, browser)) | ||
| .SetMethod("isAeroGlassEnabled", &App::IsAeroGlassEnabled) | ||
| .SetMethod("removeAsDefaultProtocolClient", |
There was a problem hiding this comment.
Should we provide this API on other platforms even if it does nothing? It is a bit weird that all platforms have set but only one platform has remove.
The APIs are part of the |
40356dd to
05e4f96
Compare
|
@zcbenz: Good point. I added the API to both OS X and Linux, where it just returns I incorporated all feedback, this should now be good 👍 |
05e4f96 to
1231360
Compare
|
👍 |
|
Is there really nothing that can be done for Linux users? etc.. |
Because there isn't an unified way to do it across distributions. |
|
Some (most popular) distributions is better than nothing. |
Unfortunately targeting distributions will be a shot in the dark. As some of the links you pointed out the configuration is done via the window manager or desktop environment. So it's not performed by the OS itself but by Gnome, KDE, XFCE, xdg-open, or some other shell or program. It isn't always promised a distribution will have either of the necessary programs to do this. Even if they do have a shell such a Gnome installed it could still be possible they don't have gnome-open available. Even if you know the distro is ships with them it is possible the user can remove them. |
|
I suppose checking for gnome-open, exo-open, xdg-open, gvfs-open, or kde-open and using which ever is available might be better than nothing though. You wouldn't target a distro but you could target possible common environments. |
This PR adds an API enabling Electron to set itself as the default protocol handler for a custom protocol on both OS X and Windows. The API uses the Windows Registry and LSSetDefaultHandlerForURLScheme internally.
app.setAsDefaultProtocolClient(protocol)protocolString - The name of your protocol, without://. If you want your app to handleelectron://links, call this method withelectronas the parameter.This method sets the current executable as the default handler for a protocol (aka URI scheme). It allows you to integrate your app deeper into the operating system. Once registered, all links with
your-protocol://will be openend with the current executable. The whole link, including protocol, will be passed to your application as a parameter.On OS X, one can only register protocols that have been added to the app's
info.plist, which can not be modified at runtime (and is therefore not part of the API). You can however change the file with a simple text editor or script during build time.app.removeAsDefaultProtocolClient(protocol)WindowsprotocolString - The name of your protocol, without://.This method checks if the current executable as the default handler for a protocol (aka URI scheme). If so, it will remove the app as the default handler. On OS X, removing the app will automatically remove the app as the default protocol handler.
Closes #4857 || cc @paulcbetts @zcbenz @kevinsawicki