Open sourcing a backend for auto-updating Electron apps
We wanted to make auto-updating Electron apps painless. Therefore, we developed an open source backend implementation for to manage release information more easily.
Automating the Squirrel framework with the autoUpdater module
Squirrel checks for new releases and handles an upgrade for (including downloading the new build and installing it upon restart). From the client side, that’s everything you need for Electron. However, Squirrel needs an endpoint, which means we needed a server to host. We wanted to host our build information on the cloud as well for convenience.
Here is a brief flow of how the auto update is done:
First, Squirrel will check for updates from the endpoint server. The server’s main job is to fetch information from the GitHub repository assigned. If the new release is different from the current app, Squirrel will trigger an update.
How do they communicate? The little Squirrel tells the endpoint what platform and version the current app is on:
The server then compares it with the latest version. If the latest version > current version, it responds with the URL pointing to the latest version:
If no update is required, your server must respond with a status code of 204 No Content. Squirrel will check for an update again at the interval specified.
Manage your releases on GitHub
To release a new version of the application, we need to package it for Mac and Windows respectively. We recommend using electron-builder. Here is the minimal electron-builder configuration:
"appId": "<your app id>",
With the above configuration, we will get
.zipfor the Mac application
.exefor the Windows application. The
.nupkgis for squirrel update, and the
.exeis for first time installation.
Then we need to host the app releases and the endpoint server for Squirrel somewhere. We appreciate simplicity. We find storing assets using GitHub release can simplify the process in these ways:
- Don’t have to set up a database
- Don’t need to manually check for new releases
- Set up an authentication system easily
We can just push a tag — if we have set up our automatic build tool. A CI tool will do the build job and pin up a release. Alternatively, we could also manually add a new release and all the assets files.
One of our applications, MakeAppIcon Desktop, uses this backend to update its version automatically.
Let’s say we have these Releases on GitHub:
v1.0.4 - makeappicon-osx.zip
v1.0.0 - makeappicon-osx.zip
This request means: the current app is a Mac app, and the version is 1.0.0
200 OK -
Response from the server tells the autoUpdater: there is an update available (response code 200) and returns a URL.
Problems that we may encounter when packaging the app
Packaging the app on different platforms might sometimes have hiccups. Below are some of the known issues and some hints to get through them.
AutoUpdater on Mac application throws authentication errors
- Make sure you have signed your app, both the latest version being updated to and the version on the user computer running the update. Running
electron .on your development machine will not work.
- Code signing is not required for Windows applications, but you will get that ugly “Unknown Publisher” warning.
- Your are using HTTPS instead of HTTP in all network traffic between autoUpdater and the Squirrel endpoint. That means, the URL returned by the squirrel endpoint also needs to be HTTPS:
OSStatus error -60006 on Mac applications
- Read this GitHub issue
OSStatus error -60005 on Mac applications
- Double check the
URLreturned by your Squirrel server is using HTTPS.
- If your Squirrel endpoint is parsing the incoming request protocol to use as the protocol for
URL, there is a chance that when you deploy your Squirrel endpoint to a cloud server, the inbound requests are passing through a proxy, so they become HTTP when they reach your Squirrel endpoint application. As a result, the
URLis returned with a HTTP URL
How to get the
autoUpdater to work on Windows
- Read this tutorial
The Windows application crashes with
Squirrel not found when launching
- If you are not using the electron-builder to build you app, you have to make sure you build your Windows application with Squirrel. Some packagers do not include it by default.
Our open source project enables you to deploy for free
We have open-sourced an endpoint server for the convenience of Electron developers to deploy the server for free on Skygear, our open source backend. It will take around 5 minutes to set up the complete server. Please read our set up guide on GitHub for the detailed steps deploying the Squirrel server.
skygear-squirrel-server - Squirrel endpoint using GitHub as a backend.
Besides Electron applications, it also works for any application using the Squirrel framework.
Contributions are welcome!
There are still some challenges when we implement the server for Squirrel. Fetching private repository requires GitHub Auth token and file caching (see issue), so it only supports releases from public repositories at this moment.