如何将第三方二进制文件与Electron捆绑在一起? [英] How to bundle a third party binary with Electron?

查看:486
本文介绍了如何将第三方二进制文件与Electron捆绑在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总体而言,我还是电子生态系统和台式机开发的新手,但我想做的是与软件捆绑在一起的第三方开放源代码应用程序交互.首先,我不确定要分发的软件包选项应该是什么.习惯上有两次下载,一次是针对已经安装了第三方二进制文件的用户,另一次是包含该二进制文件的用户?另外,我该如何实际打包和安装二进制文件?这应该是我的package.json上的一个选项吗?我应该执行哪种脚本?是否有任何npm模块可简化此操作?

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 -即使用户先前未安装节点,是否也可以从main.js调用npm?我知道节点与电子封装捆绑在一起,但是npm也是吗?

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?

-在这种情况下,二进制文件是PostgreSQL

-The binary in this case is PostgreSQL

推荐答案

我想到了两个选择.

  1. 捆绑带有您的应用程序的第三方安装程序.这是我最近所做的.在第一次运行时,我检查所需的服务是否已安装/正在运行,否则,请致电第三方安装程序/将其启动.当安装程序退出时,我只是app.relaunch()并开始使用它.当然,您需要为计划支持的每个平台安装程序.而且,您必须找出方法来检查每个平台是否已正确安装该软件.

  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.

与您的应用捆绑在一起的二进制文件.当然,您可以使用电子应用程序捆绑几乎所有东西.同样,对于计划支持的每个平台,您都将需要二进制文件.当然,它们不应该链接到默认用户在他的计算机上没有的任何东西,例如SDK和其他标头...

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 ...

不太方便,但是您始终可以添加一些启动消息或下载前消息,告诉用户他需要软件xy才能运行您的应用程序.

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.

1/2的导数:按需下载所需的内容.对于您的示例,这意味着检查用户的操作系统和体系结构,然后仅下载所需的安装程序或二进制文件(如果可用).您也可以在用户的​​计算机上构建内容,尽管这可能是最糟糕/最大/最复杂的解决方案.

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.

然后是类似 https://www.npmjs.com/package/pg -您应该始终检查npm是否有人已经构建了您所需的内容;)

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.

这篇关于如何将第三方二进制文件与Electron捆绑在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆