How to add auto-updates to your Electron application: An up to date guide
Lately, I’ve been busy creating and maintaining Zulip’s desktop client. It’s been fun and challenging to use HTML/CSS/JavaScript for creating native desktop applications.
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.
- Deploy!!
- 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 developing, so you gotta use something to detect it. I’ve used electron-is-dev for this 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 to your app's package.json file.
If you have any trouble adding auto-updates to your electron app, feel free to drop me a tweet 😎