Skip to content

Commit c64d2b6

Browse files
committed
[AutoUpdater] add documentation
1 parent 03ff41b commit c64d2b6

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

docs/References/AutoUpdater.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# AutoUpdater {: .doctitle}
2+
---
3+
4+
[TOC]
5+
6+
`AutoUpdater` Enable apps to automatically update themselves.
7+
8+
9+
The `AutoUpdater` module provides an interface for the
10+
[Squirrel](https://github.com/Squirrel) framework.
11+
12+
You can quickly launch a multi-platform release server for distributing your
13+
application by using one of these projects:
14+
15+
- [nuts][nuts]: *A smart release server for your applications, using GitHub as a backend. Auto-updates with Squirrel (Mac & Windows)*
16+
- [squirrel-updates-server][squirrel-updates-server]: *A simple node.js server
17+
for Squirrel.Mac and Squirrel.Windows which uses GitHub releases*
18+
- [squirrel-release-server][squirrel-release-server]: *A simple PHP application for Squirrel.Windows which reads updates from a folder. Supports delta updates.*
19+
20+
## Synopsis
21+
```javascript
22+
// listen to error events
23+
nw.AutoUpdater.on('error', function(msg){
24+
console.log(msg);
25+
});
26+
27+
// listen to update-downloaded event
28+
nw.AutoUpdater.on('update-downloaded', function(releaseNotes, releaseName, releaseDate, updateURL){
29+
console.log(releaseNotes);
30+
console.log(releaseName);
31+
console.log(releaseDate);
32+
console.log(updateURL);
33+
nw.AutoUpdater.QuitAndInstall();
34+
});
35+
36+
// set the update feed url
37+
nw.AutoUpdater.SetFeedURL('file:///tmp/nwjs.autoupdate.json');
38+
// the real autoupdate
39+
nw.AutoUpdater.CheckForUpdates();
40+
```
41+
42+
## Platform notices
43+
44+
Though `AutoUpdater` provides a uniform API for different platforms, there are
45+
still some subtle differences on each platform.
46+
47+
### macOS
48+
49+
On macOS, the `AutoUpdater` module is built upon [Squirrel.Mac][squirrel-mac],
50+
meaning you don't need any special setup to make it work. For server-side
51+
requirements, you can read [Server Support][server-support]. Note that [App
52+
Transport Security](https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW35) (ATS) applies to all requests made as part of the
53+
update process. Apps that need to disable ATS can add the
54+
`NSAllowsArbitraryLoads` key to their app's plist.
55+
56+
**Note:** Your application must be signed for automatic updates on macOS.
57+
This is a requirement of `Squirrel.Mac`.
58+
59+
We have a [test script](../../test/manual/autoupdate) to quickly test if the autoupdate feature is working.
60+
run 'autoupdate.sh' from the folder, it needs 2 parameters:
61+
* `IDENTITY` is your developer id, to sign the app
62+
* `DIRECTORY` is your nwjs.app location
63+
64+
### Windows
65+
66+
On Windows, you have to install your app into a user's machine before you can
67+
use the `AutoUpdater`, so it is recommended that you use the
68+
[electron-winstaller][installer-lib], [electron-builder][electron-builder-lib] or the [grunt-electron-installer][installer] package to generate a Windows installer.
69+
70+
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](https://github.com/mongodb-js/electron-squirrel-startup) to get desktop shortcuts for your app.
71+
72+
The installer generated with Squirrel will create a shortcut icon with an
73+
[Application User Model ID][app-user-model-id] in the format of
74+
`com.squirrel.PACKAGE_ID.YOUR_EXE_WITHOUT_DOT_EXE`, examples are
75+
`com.squirrel.slack.Slack` and `com.squirrel.code.Code`. You have to use the
76+
same ID for your app with `app.setAppUserModelId` API, otherwise Windows will
77+
not be able to pin your app properly in task bar.
78+
79+
The server-side setup is also different from macOS. You can read the documents of
80+
[Squirrel.Windows][squirrel-windows] to get more details.
81+
82+
### Linux
83+
84+
There is no built-in support for auto-updater on Linux, so it is recommended to
85+
use the distribution's package manager to update your app.
86+
87+
## AutoUpdater.SetFeedURL(url)
88+
89+
* `url` String
90+
91+
Sets the `url` and initialize the auto updater.
92+
93+
## AutoUpdater.GetFeedURL()
94+
95+
Returns `String` - The current update feed URL.
96+
97+
## AutoUpdater.CheckForUpdates()
98+
99+
Asks the server whether there is an update. You must call `setFeedURL` before
100+
using this API.
101+
102+
## AutoUpdater.QuitAndInstall()
103+
104+
Restarts the app and installs the update after it has been downloaded. It
105+
should only be called after `update-downloaded` has been emitted.
106+
107+
## Event: error (msg)
108+
109+
Emitted when there is an error while updating.
110+
111+
## Event: checking-for-update
112+
113+
Emitted when checking if an update has started.
114+
115+
## Event: update-available
116+
117+
Emitted when there is an available update. The update is downloaded
118+
automatically.
119+
120+
## Event: update-not-available
121+
122+
Emitted when there is no available update.
123+
124+
## Event: update-downloaded (releaseNotes, releaseName, releaseDate, updateURL)
125+
126+
Emitted when an update has been downloaded, with following parameters:
127+
128+
* `releaseNotes` String
129+
* `releaseName` String, macOS only, NOT available on windows
130+
* `releaseDate` Date
131+
* `updateURL` String
132+
133+
[squirrel-mac]: https://github.com/Squirrel/Squirrel.Mac
134+
[server-support]: https://github.com/Squirrel/Squirrel.Mac#server-support
135+
[squirrel-windows]: https://github.com/Squirrel/Squirrel.Windows
136+
[installer]: https://github.com/electron/grunt-electron-installer
137+
[installer-lib]: https://github.com/electron/windows-installer
138+
[electron-builder-lib]: https://github.com/electron-userland/electron-builder
139+
[app-user-model-id]: https://msdn.microsoft.com/en-us/library/windows/desktop/dd378459(v=vs.85).aspx
140+
[squirrel-updates-server]: https://github.com/Aluxian/squirrel-updates-server
141+
[nuts]: https://github.com/GitbookIO/nuts
142+
[squirrel-release-server]: https://github.com/Arcath/squirrel-release-server

0 commit comments

Comments
 (0)