How to bundle a third party binary with Electron?
Asked Answered
F

1

9

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

Furze answered 12/8, 2016 at 13:14 Comment(2)
Looking for a similar answer too. In the case of having some kind of storage bundled with the application you could just use SQLite, which is just a .sqlite file, so no binaries to include.Hugmetight
See this similar question: #33153033Haynie
O
5

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.

Overlie answered 7/12, 2016 at 17:55 Comment(2)
I think this discussion could be helpful to get more into the point: #33153033Antecede
The linked package is a client for connecting to and querying postgres. It doesn't replace the need for the binary.Meal

© 2022 - 2024 — McMap. All rights reserved.