Last active
August 23, 2020 18:48
-
-
Save juliangruber/27ea9c03aa929610f871376b3c30c39c to your computer and use it in GitHub Desktop.
Here is how to accept files dropped on an @electronjs app's icon in osx. For this to work you need to properly package the app into a `.app`, and to place the CFBundleDocumentTypes spec into it's Info.plist. Here we're using electron-packager.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>CFBundleDocumentTypes</key> | |
<array> | |
<dict> | |
<key>CFBundleTypeName</key> | |
<string>All Files</string> | |
<key>LSHandlerRank</key> | |
<string>Alternate</string> | |
<key>LSItemContentTypes</key> | |
<array> | |
<string>public.data</string> | |
<string>public.content</string> | |
</array> | |
</dict> | |
</array> | |
</dict> | |
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
app.on('will-finish-launching', () => { | |
app.on('open-file', (ev, path) => { | |
ev.preventDefault(); | |
// send the path to the renderer process via rpc | |
}); | |
}); | |
// ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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