Skip to content

Commit 16bc53c

Browse files
committed
fix: Download update from public Github repo failed on Mac
Close #1388
1 parent 58061ec commit 16bc53c

File tree

7 files changed

+243
-180
lines changed

7 files changed

+243
-180
lines changed

docs/Auto Update.md

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ Simplified auto-update is not supported for Squirrel.Windows.
2020
2121
**NOTICE**:
2222
23-
1. Do not call [setFeedURL](https://github.com/electron-userland/electron-builder/wiki/Auto-Update#autoupdatersetfeedurloptions). electron-builder automatically creates `app-update.yml` file for you on build in the `resources` (this file is internal, you don't need to be aware of it).
23+
1. Do not call [setFeedURL](#module_electron-updater/out/AppUpdater.AppUpdater+setFeedURL). electron-builder automatically creates `app-update.yml` file for you on build in the `resources` (this file is internal, you don't need to be aware of it).
2424
2. Bintray provider doesn't support [macOS auto-update](https://github.com/electron-userland/electron-builder/issues/1172) currently.
25-
3. `zip` target for macOS is **required** for Squirrel.Mac, whereas `latest-mac.json` cannot be created, which causes `autoUpdater` error.
25+
3. `zip` target for macOS is **required** for Squirrel.Mac, whereas `latest-mac.json` cannot be created, which causes `autoUpdater` error. Default [target](https://github.com/electron-userland/electron-builder/wiki/Options#MacOptions-target) for macOS `dmg`+`zip`, you don't need to explicitly specify target.
2626

2727
### Examples
2828

29-
**Auto Update**
29+
#### Auto Update
3030

3131
A [complete example](https://github.com/iffy/electron-updater-example) showing how to use.
3232

33-
**Manual Update**
33+
#### Manual Update
3434

3535
The following code snippet gives another example, which illustrate an encapsulated manual update via menu.
3636

@@ -39,12 +39,13 @@ The following code snippet gives another example, which illustrate an encapsulat
3939
const { dialog } = require('electron')
4040
const { autoUpdater } = require('electron-updater')
4141
42-
4342
let updater
4443
autoUpdater.autoDownload = false
44+
4545
autoUpdater.on('error', (event, error) => {
4646
dialog.showErrorBox('Error: ', error)
4747
})
48+
4849
autoUpdater.on('update-available', () => {
4950
dialog.showMessageBox({
5051
type: 'info',
@@ -54,12 +55,14 @@ autoUpdater.on('update-available', () => {
5455
}, (buttonIndex) => {
5556
if (buttonIndex === 0) {
5657
autoUpdater.downloadUpdate()
57-
} else {
58+
}
59+
else {
5860
updater.enabled = true
5961
updater = null
6062
}
6163
})
6264
})
65+
6366
autoUpdater.on('update-not-available', () => {
6467
dialog.showMessageBox({
6568
title: 'No Updates',
@@ -68,6 +71,7 @@ autoUpdater.on('update-not-available', () => {
6871
updater.enabled = true
6972
updater = null
7073
})
74+
7175
autoUpdater.on('update-downloaded', () => {
7276
dialog.showMessageBox({
7377
title: 'Install Updates',
@@ -77,7 +81,6 @@ autoUpdater.on('update-downloaded', () => {
7781
})
7882
})
7983
80-
8184
// export this to MenuItem click callback
8285
function checkForUpdates (menuItem, focusedWindow, event) {
8386
updater = menuItem
@@ -96,11 +99,14 @@ Import steps:
9699

97100
`latest.yml` (or `latest-mac.json` for macOS) will be generated and uploaded for all providers except `bintray` (because not required, `bintray` doesn't use `latest.yml`).
98101
99-
## Private Update Repo
102+
## Private GitHub Update Repo
103+
104+
You can use a private repository for updates with electron-updater by setting the `GH_TOKEN` environment variable (on user machine) and `private` option.
105+
If `GH_TOKEN` is set, electron-updater will use the GitHub API for updates allowing private repositories to work.
100106
101-
You can use a private repository for updates with electron-updater by setting the `GH_TOKEN` environment variable. If `GH_TOKEN` is set, electron-updater will use the GitHub API for updates allowing private repositories to work.
107+
Only for [very special](https://github.com/electron-userland/electron-builder/issues/1393#issuecomment-288191885) cases — not intended and not suitable for all users.
102108
103-
**Note:** The GitHub API currently has a rate limit of 5000 requests per user per hour. An update check uses up to 3 requests per check. If you are worried about hitting your rate limit, consider using [conditional requests](https://developer.github.com/v3/#conditional-requests) before checking for updates to reduce rate limit usage.
109+
**Note:** The GitHub API currently has a rate limit of 5000 requests per user per hour. An update check uses up to 3 requests per check.
104110
105111
## Debugging
106112
@@ -231,7 +237,7 @@ Emitted on progress. Only supported over Windows build, since `Squirrel.Mac` [do
231237
232238
| Param | Type |
233239
| --- | --- |
234-
| value | <code>[RequestHeaders](Developer-API#RequestHeaders)</code> &#124; <code>null</code> |
240+
| value | <code>[RequestHeaders](Developer-API#RequestHeaders)</code> \| <code>null</code> |
235241
236242
<a name="module_electron-updater/out/api.Provider+getUpdateFile"></a>
237243
@@ -326,11 +332,11 @@ Emitted on progress. Only supported over Windows build, since `Squirrel.Mac` [do
326332
* [.AppUpdater](#AppUpdater) ⇐ <code>internal:EventEmitter</code>
327333
* [`.checkForUpdates()`](#module_electron-updater/out/AppUpdater.AppUpdater+checkForUpdates) ⇒ <code>Promise&lt;[UpdateCheckResult](#UpdateCheckResult)&gt;</code>
328334
* [`.downloadUpdate(cancellationToken)`](#module_electron-updater/out/AppUpdater.AppUpdater+downloadUpdate) ⇒ <code>Promise&lt;any&gt;</code>
329-
* [`.getFeedURL()`](#module_electron-updater/out/AppUpdater.AppUpdater+getFeedURL) ⇒ <code>undefined</code> &#124; <code>null</code> &#124; <code>string</code>
335+
* [`.getFeedURL()`](#module_electron-updater/out/AppUpdater.AppUpdater+getFeedURL) ⇒ <code>undefined</code> \| <code>null</code> \| <code>string</code>
330336
* [`.setFeedURL(options)`](#module_electron-updater/out/AppUpdater.AppUpdater+setFeedURL)
331337
* [`.loadUpdateConfig()`](#module_electron-updater/out/AppUpdater.AppUpdater+loadUpdateConfig) ⇒ <code>Promise&lt;any&gt;</code>
332338
* [`.quitAndInstall()`](#module_electron-updater/out/AppUpdater.AppUpdater+quitAndInstall)
333-
* [`.computeRequestHeaders(fileInfo)`](#module_electron-updater/out/AppUpdater.AppUpdater+computeRequestHeaders) ⇒ <code>null</code> &#124; <code>[RequestHeaders](Developer-API#RequestHeaders)</code>
339+
* [`.computeRequestHeaders(fileInfo)`](#module_electron-updater/out/AppUpdater.AppUpdater+computeRequestHeaders) ⇒ <code>null</code> \| <code>[RequestHeaders](Developer-API#RequestHeaders)</code>
334340
* [`.dispatchError(e)`](#module_electron-updater/out/AppUpdater.AppUpdater+dispatchError)
335341
* [`.doDownloadUpdate(versionInfo, fileInfo, cancellationToken)`](#module_electron-updater/out/AppUpdater.AppUpdater+doDownloadUpdate) ⇒ <code>Promise&lt;any&gt;</code>
336342
* [`.onUpdateAvailable(versionInfo, fileInfo)`](#module_electron-updater/out/AppUpdater.AppUpdater+onUpdateAvailable)
@@ -381,11 +387,11 @@ Emitted on progress. Only supported over Windows build, since `Squirrel.Mac` [do
381387
* [.AppUpdater](#AppUpdater) ⇐ <code>internal:EventEmitter</code>
382388
* [`.checkForUpdates()`](#module_electron-updater/out/AppUpdater.AppUpdater+checkForUpdates) ⇒ <code>Promise&lt;[UpdateCheckResult](#UpdateCheckResult)&gt;</code>
383389
* [`.downloadUpdate(cancellationToken)`](#module_electron-updater/out/AppUpdater.AppUpdater+downloadUpdate) ⇒ <code>Promise&lt;any&gt;</code>
384-
* [`.getFeedURL()`](#module_electron-updater/out/AppUpdater.AppUpdater+getFeedURL) ⇒ <code>undefined</code> &#124; <code>null</code> &#124; <code>string</code>
390+
* [`.getFeedURL()`](#module_electron-updater/out/AppUpdater.AppUpdater+getFeedURL) ⇒ <code>undefined</code> \| <code>null</code> \| <code>string</code>
385391
* [`.setFeedURL(options)`](#module_electron-updater/out/AppUpdater.AppUpdater+setFeedURL)
386392
* [`.loadUpdateConfig()`](#module_electron-updater/out/AppUpdater.AppUpdater+loadUpdateConfig) ⇒ <code>Promise&lt;any&gt;</code>
387393
* [`.quitAndInstall()`](#module_electron-updater/out/AppUpdater.AppUpdater+quitAndInstall)
388-
* [`.computeRequestHeaders(fileInfo)`](#module_electron-updater/out/AppUpdater.AppUpdater+computeRequestHeaders) ⇒ <code>null</code> &#124; <code>[RequestHeaders](Developer-API#RequestHeaders)</code>
394+
* [`.computeRequestHeaders(fileInfo)`](#module_electron-updater/out/AppUpdater.AppUpdater+computeRequestHeaders) ⇒ <code>null</code> \| <code>[RequestHeaders](Developer-API#RequestHeaders)</code>
389395
* [`.dispatchError(e)`](#module_electron-updater/out/AppUpdater.AppUpdater+dispatchError)
390396
* [`.doDownloadUpdate(versionInfo, fileInfo, cancellationToken)`](#module_electron-updater/out/AppUpdater.AppUpdater+doDownloadUpdate) ⇒ <code>Promise&lt;any&gt;</code>
391397
* [`.onUpdateAvailable(versionInfo, fileInfo)`](#module_electron-updater/out/AppUpdater.AppUpdater+onUpdateAvailable)
@@ -421,7 +427,7 @@ Configure update provider. If value is `string`, [module:electron-builder-http/o
421427
422428
| Param | Type | Description |
423429
| --- | --- | --- |
424-
| options | <code>[PublishConfiguration](Publishing-Artifacts#PublishConfiguration)</code> &#124; <code>[GenericServerOptions](Publishing-Artifacts#GenericServerOptions)</code> &#124; <code>[S3Options](Publishing-Artifacts#S3Options)</code> &#124; <code>[BintrayOptions](Publishing-Artifacts#BintrayOptions)</code> &#124; <code>[GithubOptions](Publishing-Artifacts#GithubOptions)</code> &#124; <code>string</code> | If you want to override configuration in the `app-update.yml`. |
430+
| options | <code>[PublishConfiguration](Publishing-Artifacts#PublishConfiguration)</code> \| <code>[GenericServerOptions](Publishing-Artifacts#GenericServerOptions)</code> \| <code>[S3Options](Publishing-Artifacts#S3Options)</code> \| <code>[BintrayOptions](Publishing-Artifacts#BintrayOptions)</code> \| <code>[GithubOptions](Publishing-Artifacts#GithubOptions)</code> \| <code>string</code> | If you want to override configuration in the `app-update.yml`. |
425431
426432
<a name="module_electron-updater/out/AppUpdater.AppUpdater+loadUpdateConfig"></a>
427433

0 commit comments

Comments
 (0)