Skip to content

Commit

Permalink
feat(electron-updater): Electron Auto Updater MacOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jan 14, 2017
1 parent f0a553a commit 067d5c7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
35 changes: 23 additions & 12 deletions docs/Auto Update.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,51 @@
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)).

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.


**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.
Real project [example](https://github.com/develar/onshape-desktop-shell/blob/master/src/AppUpdater.ts).

## Quick Setup Guide

1. Install `electron-auto-updater` as app dependency.
1. Install `electron-auto-updater` as an app dependency.

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

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

```js
import {autoUpdater} from "electron-auto-updater"
```

`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.
```

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`:
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).
But if need, you can — for example, to explicitly configure Bintray provider:
```js
{
provider: "bintray",
owner: "actperepo",
package: "no-versions",
package: "no-versions"
}
```
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).
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.
`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).

**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.
## Debugging
You don't need to listen all events to understand what's wrong. Just set `logger`.
[electron-log](https://github.com/megahertz/electron-log) is recommended (it is an additional dependency that you can install if needed).
```js
autoUpdater.logger = require("electron-log")
autoUpdater.logger.transports.file.level = "info"
```
## Options
Name | Default | Description
--------------------|-------------------------|------------
autoDownload | true | Automatically download an update when it is found.
autoDownload | `true` | Automatically download an update when it is found.
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.
## Events
Expand Down
5 changes: 4 additions & 1 deletion packages/electron-auto-updater/src/GenericProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class GenericProvider implements Provider<UpdateInfo> {
async getLatestVersion(): Promise<UpdateInfo> {
let result: UpdateInfo | null = null
const channelFile = getChannelFilename(this.channel)
const pathname = path.posix.resolve(this.baseUrl.pathname || "/", `${channelFile}`)
try {
const pathname = path.posix.resolve(this.baseUrl.pathname || "/", `${channelFile}`)
result = await request<UpdateInfo>({hostname: this.baseUrl.hostname, port: this.baseUrl.port || "443", path: `${pathname}${this.baseUrl.search || ""}`})
}
catch (e) {
Expand All @@ -26,6 +26,9 @@ export class GenericProvider implements Provider<UpdateInfo> {
}

validateUpdateInfo(result)
if (getCurrentPlatform() === "darwin") {
(<any>result).releaseJsonUrl = url.format(Object.assign({}, this.baseUrl, {pathname: pathname}))
}
return result
}

Expand Down

0 comments on commit 067d5c7

Please sign in to comment.