Skip to content

Commit 067d5c7

Browse files
committed
feat(electron-updater): Electron Auto Updater MacOS support
1 parent f0a553a commit 067d5c7

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

docs/Auto Update.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,51 @@
1-
To benefit from auto updates, you have to implement and configure Electron's [`autoUpdater`](http://electron.atom.io/docs/latest/api/auto-updater/) module ([example](https://github.com/develar/onshape-desktop-shell/blob/master/src/AppUpdater.ts)).
2-
31
See the [Publishing Artifacts](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts) section of the [Wiki](https://github.com/electron-userland/electron-builder/wiki) for more information on how to configure your CI environment for automated deployments.
42

5-
6-
**NOTICE**: [macOS auto-update](https://github.com/electron/electron/blob/master/docs/api/auto-updater.md#macos) is not yet simplified. Update providers supported only on Windows.
3+
Real project [example](https://github.com/develar/onshape-desktop-shell/blob/master/src/AppUpdater.ts).
74

85
## Quick Setup Guide
96

10-
1. Install `electron-auto-updater` as app dependency.
7+
1. Install `electron-auto-updater` as an app dependency.
118

129
2. [Configure publish](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#PublishConfiguration).
1310

1411
3. Use `autoUpdater` from `electron-auto-updater` instead of `electron`, e.g. (ES 6):
1512

1613
```js
1714
import {autoUpdater} from "electron-auto-updater"
18-
```
19-
20-
`electron-auto-updater` works in the same way as electron bundled, it allows you to avoid conditional statements and use the same API across platforms.
15+
```
2116

22-
4. Do not call `setFeedURL` on Windows. 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). But if need, you can — for example, to explicitly set `BintrayOptions`:
17+
4. Do not call `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).
18+
19+
But if need, you can — for example, to explicitly configure Bintray provider:
2320
```js
2421
{
2522
provider: "bintray",
2623
owner: "actperepo",
27-
package: "no-versions",
24+
package: "no-versions"
2825
}
2926
```
3027
31-
Currently, `generic` (any HTTPS web server), `github` and `bintray` are supported. `latest.yml` will be generated in addition to installer for `generic` and `github` and must be uploaded also (in short: only `bintray` doesn't use `latest.yml` and this file must be not uploaded on Bintray).
28+
Currently, [generic](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#GenericServerOptions) (any HTTPS web server), [github](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#GithubOptions) and [bintray](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#BintrayOptions) are supported.
29+
`latest.yml` (or `latest-mac.json` for macOS) will be generated in addition to installer for `generic` and `github` and must be uploaded also (in short: only `bintray` doesn't use `latest.yml` and this file must be not uploaded on Bintray).
30+
31+
**NOTICE**: Bintray provider doesn't support [macOS auto-update](https://github.com/electron/electron/blob/master/docs/api/auto-updater.md#macos) currently. If need, please file issue.
32+
33+
## Debugging
34+
35+
You don't need to listen all events to understand what's wrong. Just set `logger`.
36+
[electron-log](https://github.com/megahertz/electron-log) is recommended (it is an additional dependency that you can install if needed).
37+
38+
```js
39+
autoUpdater.logger = require("electron-log")
40+
autoUpdater.logger.transports.file.level = "info"
41+
```
3242
3343
## Options
3444
3545
Name | Default | Description
3646
--------------------|-------------------------|------------
37-
autoDownload | true | Automatically download an update when it is found.
47+
autoDownload | `true` | Automatically download an update when it is found.
48+
logger | `console` | The logger. You can pass [electron-log](https://github.com/megahertz/electron-log), [winston](https://github.com/winstonjs/winston) or another logger with the following interface: `{ info(), warn(), error() }`. Set it to `null` if you would like to disable a logging feature.
3849
3950
## Events
4051

packages/electron-auto-updater/src/GenericProvider.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export class GenericProvider implements Provider<UpdateInfo> {
1414
async getLatestVersion(): Promise<UpdateInfo> {
1515
let result: UpdateInfo | null = null
1616
const channelFile = getChannelFilename(this.channel)
17+
const pathname = path.posix.resolve(this.baseUrl.pathname || "/", `${channelFile}`)
1718
try {
18-
const pathname = path.posix.resolve(this.baseUrl.pathname || "/", `${channelFile}`)
1919
result = await request<UpdateInfo>({hostname: this.baseUrl.hostname, port: this.baseUrl.port || "443", path: `${pathname}${this.baseUrl.search || ""}`})
2020
}
2121
catch (e) {
@@ -26,6 +26,9 @@ export class GenericProvider implements Provider<UpdateInfo> {
2626
}
2727

2828
validateUpdateInfo(result)
29+
if (getCurrentPlatform() === "darwin") {
30+
(<any>result).releaseJsonUrl = url.format(Object.assign({}, this.baseUrl, {pathname: pathname}))
31+
}
2932
return result
3033
}
3134

0 commit comments

Comments
 (0)