⚠️ This lesson is retired and might contain outdated information.

Ship updates to your Electron app with `autoUpdater` (Windows)

Cameron Nokes
InstructorCameron Nokes
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 2 years ago

In this lesson, we'll go over a few differences in implementing auto-updates on Windows like handling Squirrel.Windows startup events and configuring electron-builder to build for a Squirrel.Windows target.

[00:00] My Hello World application here is almost complete. I have fully functioning main and renderer process codes set up. I have auto-updates working for Mac.

[00:08] Getting auto-updates working for Mac is similar to Windows, except for a few key differences. The native Windows framework that Electron AutoUpdater works with, called squirrel.windows, is a little different from squirrel.Mac.

[00:19] First thing I've done here is I've added a few additional dependencies. I've added Electron Builder Squirrel Windows. This tells Electron Builder to bundle squirrel.windows with our compiled application, and I've added Electron Squirrel Startup.

[00:34] Electron Squirrel Startup helps with a few of those Windows differences that occur when your application is started after an auto-update. We're going to go ahead and glance at this Electron Squirrel Startup's source code really quickly.

[00:46] This is Electron Squirrel Startup's main source code. You see that it exports the results of a function called check.

[00:53] In check, you can see it grabs the process arguments passed to our application, and based on those process arguments, whether they be squirrel/install or updated, it runs different commands. It says create shortcut or remove shortcut, etc.

[01:10] Squirrel.windows bundles a separate executable file with your application. This module is calling that executable. It's called update.exe, you can see right there.

[01:21] It calls update.exe and tells it to do all this stuff with your shortcuts to make sure that after update, all of your application shortcuts in Windows are pointing to the correct application version, etc. Let's see how we integrate that with our code.

[01:35] In our main.js, in our main process, and this is really simple, we're just going to require it. Remember, it exports the results of that function, so that function is true.

[01:49] What we want to do is exit out of our application because Squirrel's going to do its stuff, and then it's going to quit our application and restart it. That's super simple, and that handles some auto-updating work that we need on Windows.

[02:05] In our package.json, we need to add some additional configuration to our Electron Builder config, so add Squirrel Windows, and we need to provide an actual URL for the icon.

[02:19] For our purposes, I'm going to use our update server, which we have running locally, and I've already put our ICO file on there. In production, ideally, this is an HTTPS URL.

[02:33] We have to explicitly set a bill target for squirrel.windows, so we're just going to add that here. This is why we needed to add Electron Builder squirrel/windows as a dependency.

[02:44] Let's jump onto Windows and run our build scripts. We're going to run our build assets/buildWin, that CMB script. Our build script completed. We have our version 1.00I already have my update server running that's serving 1.01 on it, so let's run the installer here to set it up. Our application started with version 1.00and then we have an update available, so let's update our application. Now we're on 1.01. Awesome, it worked.

[03:13] On our desktop, we can see that Squirrel has added a shortcut on our desktop for us, and if we inspect it, the start-in field, and go to the very end, we can see that it is telling it to start the 1.01 version. We can see the Squirrel behind the scenes has handled adding a shortcut, and then updating it appropriately.

Imran Khan
Imran Khan
~ 6 years ago

Hi Cameron, Great stuff!! Can you please share the server code? Thanks.

Markdown supported.
Become a member to join the discussionEnroll Today