Open sourcing a backend for auto-updating Electron apps

By David Ng, Product & Growth, Oursky

So you’ve used Electron to build an amazing cross-platform application with JavaScript, HTML and CSS. What happens if you’ve updated? How will you push your updates to your users’ platform?
 
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

We created the Electron autoUpdater module to provide an interface for the Squirrel framework.

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:

https://squirrel.endpoint/update/platform=osx&version=1.0.0

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:

{
"url": "http://mycompany.com/myapp/releases/latest",
}

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>",
"mac": {
"target": ["zip"],
},
"win": {
"target": "squirrel",
},
"squirrelWindows": {
"useAppIdAsId": true
}
}

With the above configuration, we will get

  • .zip for the Mac application
  • a RELEASES , a .nupkg and a .exe for the Windows application. The .nupkg is for squirrel update, and the .exe is 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.

Case Example

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

Request:

/update?platform=osx&version=1.0.0
 
This request means: the current app is a Mac app, and the version is 1.0.0

Response

200 OK - {"url": "https://makeappicon-github-repo-url/v1.0.4/makeappicon-osx.zip"}
 
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:{"url": "https://....."}

OSStatus error -60006 on Mac applications

OSStatus error -60005 on Mac applications

  • Double check the URL returned 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 URL is returned with a HTTP URL

How to get the autoUpdater to work on Windows

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.

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.


If you have any feedback, please open an issue or create a pull request ;)

Building an app? Our free developer tools and open source backend will make your job easier.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.