2015-08-19 16:55:11 +00:00
# autoUpdater
2013-08-14 22:43:35 +00:00
2016-04-22 18:42:54 +00:00
> Enable apps to automatically update themselves.
2016-04-21 22:35:29 +00:00
2016-05-19 09:32:43 +00:00
The `autoUpdater` module provides an interface for the
[Squirrel ](https://github.com/Squirrel ) framework.
2015-03-04 22:36:56 +00:00
2016-03-31 05:16:14 +00:00
You can quickly launch a multi-platform release server for distributing your
2016-04-01 11:28:52 +00:00
application by using one of these projects:
2016-06-01 13:12:49 +00:00
- [nuts][nuts]: *A smart release server for your applications, using GitHub as a backend. Auto-updates with Squirrel (Mac & Windows)*
2016-04-22 13:53:26 +00:00
- [electron-release-server][electron-release-server]: *A fully featured,
self-hosted release server for electron applications, compatible with
auto-updater*
- [squirrel-updates-server][squirrel-updates-server]: *A simple node.js server
for Squirrel.Mac and Squirrel.Windows which uses GitHub releases*
2016-03-22 23:35:03 +00:00
2015-10-23 12:11:59 +00:00
## Platform notices
2014-05-05 02:07:15 +00:00
2015-11-01 02:25:07 +00:00
Though `autoUpdater` provides a uniform API for different platforms, there are
2015-10-23 12:11:59 +00:00
still some subtle differences on each platform.
2014-05-05 02:07:15 +00:00
2016-06-18 13:26:26 +00:00
### macOS
2014-07-25 16:14:49 +00:00
2016-06-18 13:26:26 +00:00
On macOS, the `autoUpdater` module is built upon [Squirrel.Mac][squirrel-mac],
2015-11-03 07:30:54 +00:00
meaning you don't need any special setup to make it work. For server-side
requirements, you can read [Server Support][server-support].
2014-05-05 02:07:15 +00:00
2016-06-18 13:26:26 +00:00
**Note:** Your application must be signed for automatic updates on macOS.
2016-04-07 00:40:07 +00:00
This is a requirement of `Squirrel.Mac` .
2015-10-23 12:11:59 +00:00
### Windows
2014-05-05 02:07:15 +00:00
2015-11-03 07:30:54 +00:00
On Windows, you have to install your app into a user's machine before you can
2016-05-06 17:05:12 +00:00
use the `autoUpdater` , so it is recommended that you use the
2016-06-12 08:48:50 +00:00
[electron-winstaller][installer-lib], [electron-builder][electron-builder-lib] or the [grunt-electron-installer][installer] package to generate a Windows installer.
2015-11-03 07:30:54 +00:00
2016-09-09 18:51:42 +00:00
When using [electron-winstaller][installer-lib] or [electron-builder][electron-builder-lib] make sure you do not try to update your app [the first time it runs ](https://github.com/electron/windows-installer#handling-squirrel-events ) (Also see [this issue for more info ](https://github.com/electron/electron/issues/7155 )). It's also recommended to use [electron-squirrel-startup ](electron-squirrel-startup ) to get desktop shortcuts for your app.
2015-11-03 07:30:54 +00:00
The installer generated with Squirrel will create a shortcut icon with an
[Application User Model ID][app-user-model-id] in the format of
`com.squirrel.PACKAGE_ID.YOUR_EXE_WITHOUT_DOT_EXE` , examples are
`com.squirrel.slack.Slack` and `com.squirrel.code.Code` . You have to use the
same ID for your app with `app.setAppUserModelId` API, otherwise Windows will
not be able to pin your app properly in task bar.
2014-05-05 02:07:15 +00:00
2016-06-18 13:26:26 +00:00
The server-side setup is also different from macOS. You can read the documents of
2015-10-23 12:11:59 +00:00
[Squirrel.Windows][squirrel-windows] to get more details.
2014-05-05 02:07:15 +00:00
2015-10-23 12:11:59 +00:00
### Linux
2014-05-05 02:07:15 +00:00
2015-12-14 00:02:30 +00:00
There is no built-in support for auto-updater on Linux, so it is recommended to
2015-10-23 12:11:59 +00:00
use the distribution's package manager to update your app.
2015-08-30 22:07:36 +00:00
2015-08-19 16:55:11 +00:00
## Events
The `autoUpdater` object emits the following events:
### Event: 'error'
Returns:
2015-04-07 16:21:29 +00:00
2015-10-23 06:36:36 +00:00
* `error` Error
2015-04-07 16:21:29 +00:00
2015-07-23 16:57:42 +00:00
Emitted when there is an error while updating.
2015-04-07 16:21:29 +00:00
2015-08-19 16:55:11 +00:00
### Event: 'checking-for-update'
2013-08-14 22:43:35 +00:00
2015-07-28 15:51:41 +00:00
Emitted when checking if an update has started.
2013-08-14 22:43:35 +00:00
2015-08-19 16:55:11 +00:00
### Event: 'update-available'
2014-02-02 12:37:46 +00:00
2015-07-23 16:57:42 +00:00
Emitted when there is an available update. The update is downloaded
2014-02-02 12:37:46 +00:00
automatically.
2015-08-19 16:55:11 +00:00
### Event: 'update-not-available'
2013-08-14 22:43:35 +00:00
2014-02-02 12:37:46 +00:00
Emitted when there is no available update.
2013-08-14 22:43:35 +00:00
2015-08-19 16:55:11 +00:00
### Event: 'update-downloaded'
Returns:
2013-08-14 22:43:35 +00:00
* `event` Event
2014-02-02 12:37:46 +00:00
* `releaseNotes` String
* `releaseName` String
* `releaseDate` Date
2015-11-13 08:03:40 +00:00
* `updateURL` String
2013-08-14 22:43:35 +00:00
2015-10-23 07:50:55 +00:00
Emitted when an update has been downloaded.
2013-08-14 22:43:35 +00:00
2015-10-23 12:11:59 +00:00
On Windows only `releaseName` is available.
2015-08-19 16:55:11 +00:00
## Methods
The `autoUpdater` object has the following methods:
2016-06-10 13:55:42 +00:00
### `autoUpdater.setFeedURL(url[, requestHeaders])`
2013-08-14 22:43:35 +00:00
* `url` String
2016-06-18 13:26:26 +00:00
* `requestHeaders` Object _macOS_ - HTTP request headers.
2013-08-14 22:43:35 +00:00
2016-06-10 13:55:42 +00:00
Sets the `url` and initialize the auto updater.
2013-08-14 22:43:35 +00:00
2016-07-14 12:07:17 +00:00
### `autoUpdater.getFeedURL()`
Returns the current update feed URL.
2015-08-19 16:55:11 +00:00
### `autoUpdater.checkForUpdates()`
2013-08-14 22:43:35 +00:00
2015-11-13 08:03:40 +00:00
Asks the server whether there is an update. You must call `setFeedURL` before
2014-02-02 12:37:46 +00:00
using this API.
2015-10-23 07:50:55 +00:00
2015-10-30 11:17:30 +00:00
### `autoUpdater.quitAndInstall()`
2015-10-23 07:50:55 +00:00
2015-11-03 07:30:54 +00:00
Restarts the app and installs the update after it has been downloaded. It
should only be called after `update-downloaded` has been emitted.
2015-10-23 12:11:59 +00:00
[squirrel-mac]: https://github.com/Squirrel/Squirrel.Mac
[server-support]: https://github.com/Squirrel/Squirrel.Mac#server-support
[squirrel-windows]: https://github.com/Squirrel/Squirrel.Windows
2016-05-06 17:05:12 +00:00
[installer]: https://github.com/electron/grunt-electron-installer
[installer-lib]: https://github.com/electron/windows-installer
2016-06-12 08:48:50 +00:00
[electron-builder-lib]: https://github.com/electron-userland/electron-builder
2015-11-03 07:30:54 +00:00
[app-user-model-id]: https://msdn.microsoft.com/en-us/library/windows/desktop/dd378459(v=vs.85).aspx
2016-03-31 05:16:14 +00:00
[electron-release-server]: https://github.com/ArekSredzki/electron-release-server
2016-04-01 11:28:52 +00:00
[squirrel-updates-server]: https://github.com/Aluxian/squirrel-updates-server
2016-06-01 13:12:49 +00:00
[nuts]: https://github.com/GitbookIO/nuts