Skip to content

Instantly share code, notes, and snippets.

@juliangruber
Created May 30, 2016 20:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliangruber/c8c1c393718d7cb34fbf05ffb2729af1 to your computer and use it in GitHub Desktop.
Save juliangruber/c8c1c393718d7cb34fbf05ffb2729af1 to your computer and use it in GitHub Desktop.
Here is how to accept custom protocol links like dat://LINK in an @electronjs app, in osx. For this to work you need to properly package the app into a `.app`, and place the CFBundleURLTypes spec into it's Info.plist. Then, move the app into another directory using Finder (!). Here we're using electron-packager.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>Dat Link</string>
<key>CFBundleURLSchemes</key>
<array>
<string>dat</string>
</array>
</dict>
</array>
// ...
app.on('will-finish-launching', () => {
app.on('open-url', (ev, url) => {
ev.preventDefault();
// send the url to the renderer process via rpc
});
});
// ...
{
"scripts": {
"package": "electron-packager . --all --extend-info extend.plist"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment