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

查看:17
本文介绍了如何将第三方二进制文件与 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?我知道 node 与电子包捆绑在一起,但 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. 将第 3 方安装程序与您的应用捆绑在一起.这是我最近做的.在第一次运行时,我检查我需要的服务是否已安装/正在运行,如果没有,我会调用第 3 方安装程序/启动它.当安装程序退出时,我只需 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 ;)

我建议使用很棒的 electron-builder,它可以将东西捆绑在一起/你的应用小菜一碟.

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天全站免登陆