Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bundle a third party binary with Electron?

I am still new to the electron ecosystem and desktop development in general but what I wish to do is to interface with a third party, open source application that comes bundled in with my software. First, I am unsure on what the package options to distribute should be. Is it customary to have two downloads, one for users that already have the third party binary installed, and another one that includes it? Also how do I go about actually packaging, and installing the binary? Should this be an option on my package.json? What kind of script should I execute? Are there any npm modules to facilitate this?

edit - is it possible to invoke npm from my main.js even though a user has not previously installed node? I know node is bundled with the electron package but is npm too?

-The binary in this case is PostgreSQL

like image 739
naughty boy Avatar asked Aug 12 '16 13:08

naughty boy


1 Answers

There are a couple of options coming to my mind.

  1. Bundle a 3rd party installer w/ your app. This is what I did recently. On the first run I check if the service that I need is installed / running and if not I call the 3rd party installer / start it. When the installer quits I simply app.relaunch() and start consumig it. Of course you'll need installers for each platform you plan to support. And you'll have to figure out ways to check if the software is installed (properly) for each platform.

  2. Bundle binaries w/ you app. Of course you can bundle pretty much anything w/ your electron app. Again, you'll need binaries for each platform you plan to support. And of course they shouldn't be linked to anything that the default user doesn't have on his machine like SDKs and additional headers ...

  3. Less comfy but you can alway add some start-up message or before-download massage telling the user that he needs software xy in order to run your application.

  4. Derivate of 1/2: Download required stuff on demand. For your example this would mean checking the user's OS and arch and then just download the required installers or binaries if available. You could also build the stuff on the user's machine although this probably being the worst/biggest/most complex solution.

  5. Then there's things like https://www.npmjs.com/package/pg - you should always check npm if someone already built what you need ;)

I'd recommend using the great electron-builder which makes bundling stuff w/ your app a piece of cake.

Feel free to comment if you need more intel.

like image 153
m02ph3u5 Avatar answered Nov 11 '22 17:11

m02ph3u5