autoUpdater
Process: Main
See also: .
autoUpdater
is an EventEmitter.
Currently, only macOS and Windows are supported. There is no built-in support for auto-updater on Linux, so it is recommended to use the distribution’s package manager to update your app.
In addition, there are some subtle differences on each platform:
On macOS, the autoUpdater
module is built upon ,
meaning you don’t need any special setup to make it work. For server-side
requirements, you can read Server Support. Note that (ATS) applies to all requests made as part of the
update process. Apps that need to disable ATS can add the
NSAllowsArbitraryLoads
key to their app’s plist.
Note: Your application must be signed for automatic updates on macOS.
This is a requirement of Squirrel.Mac
.
Windows
On Windows, you have to install your app into a user’s machine before you can
use the autoUpdater
, so it is recommended that you use the
, electron-forge or the package to generate a Windows installer.
When using electron-winstaller or make sure you do not try to update your app the first time it runs (Also see ). It’s also recommended to use electron-squirrel-startup to get desktop shortcuts for your app.
Like Squirrel.Mac, Windows can host updates on S3 or any other static file host. You can read the documents of to get more details about how Squirrel.Windows works.
The autoUpdater
object emits the following events:
Event: ‘error’
Returns:
Emitted when there is an error while updating.
Event: ‘checking-for-update’
Emitted when checking if an update has started.
Emitted when there is an available update. The update is downloaded automatically.
Event: ‘update-not-available’
Emitted when there is no available update.
Event: ‘update-downloaded’
Returns:
event
EventreleaseNotes
stringreleaseName
stringreleaseDate
DateupdateURL
string
Emitted when an update has been downloaded.
Note: It is not strictly necessary to handle this event. A successfully downloaded update will still be applied the next time the application starts.
Event: ‘before-quit-for-update’
This event is emitted after a user calls quitAndInstall()
.
When this API is called, the before-quit
event is not emitted before all windows are closed. As a result you should listen to this event if you wish to perform actions before the windows are closed while a process is quitting, as well as listening to before-quit
.
The autoUpdater
object has the following methods:
options
Objecturl
stringserverType
string (optional) macOS - Can bejson
ordefault
, see the README for more information.
Sets the url
and initialize the auto updater.
autoUpdater.getFeedURL()
Returns string
- The current update feed URL.
autoUpdater.checkForUpdates()
Asks the server whether there is an update. You must call setFeedURL
before
using this API.
Note: If an update is available it will be downloaded automatically.
Calling autoUpdater.checkForUpdates()
twice will download the update two times.
autoUpdater.quitAndInstall()
Restarts the app and installs the update after it has been downloaded. It
should only be called after update-downloaded
has been emitted.
Note: It is not strictly necessary to call this function to apply an update, as a successfully downloaded update will always be applied the next time the application starts.