简体   繁体   English

如何在捆绑电子应用程序之前对其进行编码(对于Mac)?

[英]How do I code sign an Electron app before bundling it (for Mac)?

I am developing an Electron application for Mac OS X. I am attempting to test its auto-update feature while developing locally, prior to bundling it as a .app . 我正在为Mac OS X开发一个Electron应用程序。我试图在本地开发之前测试其自动更新功能, 然后将其捆绑为.app

I have a built one initial version of my application, Foo.app , along with a .dmg and .zip , using the electron-builder module, to use as the update. 我有一个我的应用程序的初始版本Foo.app ,以及.dmg.zip ,使用electron-builder模块,用作更新。 I have hosted these files. 我托管了这些文件。 I have verified that they install and run correctly. 我已经验证他们安装并正确运行。 And I have a Squirrel server, running locally, that will return a correct JSON payload pointing to that .zip . 我有一个在本地运行的Squirrel服务器,它将返回指向该.zip的正确JSON有效负载。

For developing my application locally, I am using Webpack to transpile my web assets, and using electron@1.4.4 to launch those assets in Electron. 为了在本地开发我的应用程序,我使用Webpack来转换我的Web资产,并使用electron@1.4.4在Electron中启动这些资产。 In other words, when developing locally, I am not launching the bundled .app ; 换句话说,在本地开发时,我没有启动捆绑的.app ; I am launching a dev server and serving those assets in Electron. 我正在启动一个开发服务器并在Electron中提供这些资产。 The process is similar to running $ electron . 这个过程类似于运行$ electron . .

The problem occurs when the auto-update hook is called, at this line: 在此行调用自动更新挂钩时会发生此问题:

autoUpdater.setFeedURL(feedURL)

This line raises an Electron error that says: 此行引发电子错误,表示:

"Could not get code signature for running application."

OK, so I do a search and see that there are a handful of guides that explain how to code sign an application: 好的,所以我进行搜索,看到有一些指南可以解释如何对应用程序进行编码签名:

But, these indicate that I should code sign the .app . 但是,这些表明我应该代码签署.app As I have stated, I am trying to test auto-update before I bundle it as a .app . 正如我所说,我试图在将其捆绑为.app 之前测试自动更新。 I would prefer not to rebuild again and again until I get auto-update working correctly. 我不想一次又一次地重建,直到我自动更新正常工作。

So I do another search and see there are several forum questions that are more-or-less the same as what I am asking: 所以我做了另一个搜索,看到有几个论坛问题与我要求的或多或少相同:

I'm having trouble grokking the solution from digging through these threads. 我无法通过挖掘这些线程来解决问题。 I'm hoping someone can give me a clear solution to signing an Electron app before bundling it. 我希望有人可以在捆绑之前给我一个明确的解决方案来签署Electron应用程序。


For an answer, I am hoping to get a clear answer on all of these: 对于答案,我希望得到所有这些答案的明确答案:

  • Is it possible to code sign my Electron app prior to bundling it as a .app ? 在将它捆绑为.app之前,是否可以对我的Electron应用程序进行编码签名? Ie, the files that I would launch with $ electron . 即,我将使用$ electron .启动的文件$ electron . ?
  • If yes, how? 如果有,怎么样?
  • If not, why? 如果没有,为什么? And is there any way to speed up testing this? 有没有办法加快测试?

Long shot and I have not verified this. 远射,我还没有证实这一点。

Squirrel.Mac checks the signing of the currently running application[ 1 ], this is the AppName.app/Contents/MacOS/AppName executable when you are running a packaged app. Squirrel.Mac检查当前正在运行的应用程序的签名[ 1 ],当您运行打包的应用程序时,这是AppName.app/Contents/MacOS/AppName可执行文件。 Which basically is a renamed electron executable. 这基本上是重命名的电子可执行文件。

But when you run electron . 但是当你运行electron . it will run the executable from your node/bin directory. 它将从您的node/bin目录运行可执行文件。 Electron is not signed by default, so if you sign it the auto updater might succeed with the cert check. 默认情况下未对Electron进行签名,因此如果您对其进行签名,则自动更新程序可能会成功进行证书检查。

So basically: 所以基本上:

  1. Find electron: which electron 找电子: which electron
  2. Change working directory to the electron path 将工作目录更改为电子路径
  3. Sign electron with codesign -s "Developer ID Application: YourCompanyName" electron 使用codesign -s "Developer ID Application: YourCompanyName" electron签名codesign -s "Developer ID Application: YourCompanyName" electron
  4. Validate the code signature with codesign -dvvv electron 使用codesign -dvvv electron验证代码签名

Hopefully that should cut it. 希望这应该削减它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM