How to add auto-updates to your Electron application: An up to date guide
Electron has certainly changed the way of building cross-platform desktop apps, but it’s not all rainbows and sunshine in the world of Electron. Adding and configuring automatic updates is still a challenge for most developers.
This article will cover two simple parts -
- Setting up a releases/downloads server for auto-updater
- Adding autoupdates to your app
Before proceeding to Part 1 it’s important that you’ve already packaged your app and have gotten it signed, in case you plan on adding auto-updates to a native macOS app. If that’s not the case though, you can follow the single step mentioned in this article to create an installer.
Part 1 - Setting up a releases server
To enable autoupdate you’ll need a multi-platform release server for distributing the application. For this we’re going to use nuts which is a smart release server and uses GitHub as a backend.
Deploying nuts to Herkou -
Steps to follow -
- Click on deploy to heroku button on https://github.com/GitbookIO/nuts.
- Set the necessary env variables.
- Note down the URL. It will be something like: http://yourappname.herokuapp.com
Part2 - Adding autoupdates to your code
Awesome, now let’s write some code to handle the auto-updates.
Above code will enable your app to automatically download the latest version of your app and will prompt a dialog whenever there is an update available.
There are of course other ways to implement auto-updates in your app such as adding a menu item like below:
You don’t want to check auto-updates while development, so you gotta use something to detect it. I’ve used electron-is-dev for the purpose. Also you need to handle Squirrel.Windows event on windows. For this I’ve used electron-squirrel-startup. Don’t forget to add these two modules in your apps package.json file.
(Note — This post was originally posted here — https://howtoelectron.app/)
If you have any trouble adding autoupdates to your electron app, feel free to drop me a tweet 😎
I’m Akash — a physics undergrad and a software developer based in India, focusing mostly on open source ❤ and building tiny side projects. You can find out more about me at akashnimare.in or contact me on twitter.