Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Electron automatic update feature autoUpdater


May 25, 2021 Electron


Table of contents


autoUpdater

Enable automatic updates for applications.

Procedure: main

The autoUpdater module provides an interface for the Squirrel framework.

You can distribute applications by quickly launching a multi-platform publisher using one of the following projects:

  • Nuts: Smart version server for your application, using GitHub as the backend. Automatic updates with Squirrel (Mac and Windows).
  • Electronic Publisher: A fully functional, self-published electronic application server that is compatible with automatic updates
  • Squirrel-updates-server: A simple node server for Squirrel.Mac and Squirrel.Windows.js which uses the GitHub version
  • squirrel-release-server: A simple PHP application for Squirrel.Windows that reads updates from folders. Incremental updates are supported.

Different platforms

While autoUpdater provides a unified API for different platforms, there are subtle differences on each platform.

MACOS

On macOS, the autoUpdater module is based on Squirrel.Mac, which means you don't need any special settings to make it work. F or server-side requirements, you can read Server Support. N ote that Application Transport Security (ATS) applies to all requests that are part of the update process. Applications that need to disable ATS can add the NSAllowsArbitraryLoads key to the plist of their application.

Note: Your application must be signed to automatically update macOS. That's what Squirrel.Mac asks for.


Windows


On Windows, you must install your application on the user's machine before you can use autoUpdater, so it is recommended that you use the electronic-winstaller, electron-forge, or grunt-electron-installer packages to build the Windows installer.

When using electronic-winstaller or electronic forgery, make sure that you don't try to update the application the first time you run it (see also this question for more information). It is also recommended that you use Electronic Squirrel Launch to get desktop shortcuts to your application.

The installer generated using Squirrel will create a shortcut icon for the application user model ID in the format of com.squirrel.PACKAGE_ID.YOUR_EXE_WITHOUT_DOT_EXE, as shown in com.squirrel.slack.Slack and com.squirrel.code.Code. You must use the app.setAppUserModelId API to use the same ID for your app, otherwise Windows will not be able to boot your app correctly in the taskbar.

Unlike Squirrel.Mac, Windows can host updates on S3 or any other static file host. You can read the documentation for Squirrel.Windows for more details on how Squirrel.Windows works.

Linux

There is no built-in support for automatic updates on Linux, so it is recommended to update your application using the package manager for the distribution.


Events

The autoUpdater object emits the following events:

Event: 'Error'

Return:

  • Error error

Issued when an error occurs during an update.

Event: 'Check for updates'

Check to see if the update was issued when it was started.

Event: 'Update available'

Issued when an update is available. Updates will be downloaded automatically.

Event: 'update-not-available'

Issued when no updates are available.

Event: 'Update Download'

Return:

  • Event event
  • ReleaseNotes string
  • ReleaseName string
  • releaseDate Date
  • updateURL String

Issued when the update is downloaded.

On Windows, only releaseName is available.

Method

AutoUpdater objects have the following methods:

autoUpdater.setFeedURL(url[, requestHeaders])

  • url String
  • RequestHeaders object macOS (optional) - HTTP request header.

Set the url and initialize the automatic updater.

autoUpdater.getFeedURL()

Back to String - the current update Feed URL.

autoUpdater.checkForUpdates()

Whether the request server has an update. Before you can use this API, you must call the setFeedURL.

autoUpdater.quitAndInstall()

Restart the application and download it after you install the update. It should only be called after update-downloaded.

Note: autoUpdater.quitAndInstall() will close all application windows before issuing a before-quit event after the app. This is different from the normal exit event sequence.