Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I test electron-builder auto-update flow?

I built an Electron app and I am now looking at how to distribute it. I went with electron-builder to handle packaging etc.

For a bit of context, as a web developer, I am used to continuously deploy web apps on a web server but I have a hard time figuring out how to distribute a packaged one in Electron.

In electron-builder docs there is a brief mention about testing auto-update:

"Note that in order to develop/test UI/UX of updating without packaging the application you need to have a file named dev-app-update.yml in the root of your project, which matches your publish setting from electron-builder config (but in YAML format)"

But, it's rather vague...

So I actually have two questions:

1. How do I actually test the auto-update flow?

Do I need to actually publish a new version to trigger an update locally? Seems pretty unclear, it would be like developing against the production server.

2. Is it possible to have a fallback for unsigned code?

I don't have yet any certificate for code signing. So the OS/app will block the auto-update. But, I'd still want to tell the user that an update is available so they can go and download the app manually. Can I do that? (going back to point 1, I'd like to be able to test this flow)

like image 877
Kev Avatar asked Jun 23 '18 18:06

Kev


People also ask

How do I update my Electron Forge?

Open Source Apps - update.electronjs.org Open Source apps hosted on github.com can use a free auto update service from the Electron team, update.electronjs.org . To use this with Forge, set up the GitHub publisher and add the update-electron-app module to your app.


1 Answers

I've just finished dealing with this. I also wanted to test against a non-production server and avoid having to package my app each time I iterated. To test downloads I had to sign my app, which slowed things down. But it sounds like you just need to check for updates. Which I think you can do as follows...

I created a dummy github repo, then created a a file dev-app-update.yml containing:

owner: <user or organization name>
repo: dev-auto-update-testing
provider: github

The path where this file is expected to be defaults to a place you can't access. Thankfully, you can override it like so:

    if (isDev) {
      // Useful for some dev/debugging tasks, but download can
      // not be validated becuase dev app is not signed
      autoUpdater.updateConfigPath = path.join(__dirname, 'dev-app-update.yml');
    }

...that should be enough for your case -- since you don't need downloads.

If not, here are some other tips:

  • you can change the repo setting in your electron-builder config to point at your dummy repo then package your app. This will give you a packed, production build that points at your dummy repo -- this is how I did my download testing (though I have a cert, and signed my app)
  • you should be calling autoUpdate's checkForUpdates(), but if checkForUpdatesAndNotify() gives you a useful OS Notification then you should be able to set autoUpdater.autoDownload to false and end up with what you need.

Lastly, it sounds you could skip autoUpdater, since you won't be using the download feature anyway. Instead you could use github's releases api, assuming you use github to host your release. If not then your host should have something similar. Use that to check for updates then tell the user from within your App (could present them with a clickable URL too). If you want OS Notifications electron has a module for that.

like image 107
Troy Gonsalves Avatar answered Oct 14 '22 01:10

Troy Gonsalves