Skip to content

Commit

Permalink
feat(electron-updater): add releaseNotes and releaseName to autoUpdate
Browse files Browse the repository at this point in the history
Close #1174
  • Loading branch information
develar committed Feb 1, 2017
1 parent 3987b06 commit 45c93bf
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 47 deletions.
2 changes: 2 additions & 0 deletions .github/issue_template.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<!-- Which version of electron-builder are you using? -->
* **Version**:

<!-- Which version of electron-updater are you using (if applicable)? -->

<!-- What target are you building for? -->
* **Target**:

Expand Down
50 changes: 31 additions & 19 deletions docs/Auto Update.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,41 +44,42 @@ autoUpdater.logger = require("electron-log")
autoUpdater.logger.transports.file.level = "info"
```

## Options
## Class: AppUpdater
### Properties

Name | Default | Description
--------------------|-------------------|------------
`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.
`requestHeaders` | `null` | The request headers.

## Events
### Events

The `autoUpdater` object emits the following events:

### Event: `error`

Returns:
#### Event: `error`

* `error` Error

Emitted when there is an error while updating.

### Event: `checking-for-update`
#### Event: `checking-for-update`

Emitted when checking if an update has started.

### Event: `update-available`
#### Event: `update-available`

* `info` [UpdateInfo](#UpdateInfo) for generic and github providers. [VersionInfo](#VersionInfo) for Bintray provider.

Emitted when there is an available update. The update is downloaded automatically if `autoDownload` is not set to `false`.

### Event: `update-not-available`
#### Event: `update-not-available`

Emitted when there is no available update.

### Event: `download-progress`
* `info` [UpdateInfo](#UpdateInfo) for generic and github providers. [VersionInfo](#VersionInfo) for Bintray provider.

Returns:
#### Event: `download-progress`

* `bytesPerSecond`
* `percent`
Expand All @@ -87,32 +88,43 @@ Returns:

Emitted on progress.

### Event: `update-downloaded`

Returns:
#### Event: `update-downloaded`

* `event` Event
* `info` [UpdateInfo](#UpdateInfo) for generic and github providers. [VersionInfo](#VersionInfo) for Bintray provider.

Emitted when an update has been downloaded.

## Methods
### Methods

The `autoUpdater` object has the following methods:

### `autoUpdater.setFeedURL(options)`
#### `autoUpdater.setFeedURL(options)`

* `options` GenericServerOptions | BintrayOptions | GithubOptions | string — if you want to override configuration in the `app-update.yml`.

Sets the `options`. If value is `string`, `GenericServerOptions` will be set with value as `url`.

### `autoUpdater.checkForUpdates(): Promise<UpdateCheckResult>`
#### `autoUpdater.checkForUpdates(): Promise<UpdateCheckResult>`

Asks the server whether there is an update.

### `autoUpdater.quitAndInstall()`
#### `autoUpdater.quitAndInstall()`

Restarts the app and installs the update after it has been downloaded. It
should only be called after `update-downloaded` has been emitted.

**Note:** `autoUpdater.quitAndInstall()` will close all application windows first and only emit `before-quit` event on `app` after that.
This is different from the normal quit event sequence.
This is different from the normal quit event sequence.

### VersionInfo

* `version` The version.

### UpdateInfo

Extends [VersionInfo](#VersionInfo).

* `releaseDate` The release date.
* `releaseName?` The release name.
* `releaseNotes?` The release notes.

4 changes: 4 additions & 0 deletions packages/electron-builder-http/src/publishOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export interface UpdateInfo extends VersionInfo {
readonly path: string
readonly githubArtifactName?: string | null
readonly sha2: string

readonly releaseName?: string | null
readonly releaseNotes?: string | null
readonly releaseDate: string
}

/*
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/codeSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ async function _findIdentity(type: CertType, qualifier?: string | null, keychain
}

export function findIdentity(certType: CertType, qualifier?: string | null, keychain?: string | null): Promise<string | null> {
let identity = process.env.CSC_NAME || qualifier
let identity = qualifier || process.env.CSC_NAME
if (isEmptyOrSpaces(identity)) {
if (keychain == null && !isCi && process.env.CSC_IDENTITY_AUTO_DISCOVERY === "false") {
return BluebirdPromise.resolve(null)
Expand Down
8 changes: 6 additions & 2 deletions packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ async function writeUpdateInfo(event: ArtifactCreated, _publishConfigs: Array<Pu
const updateInfoFile = isGitHub ? path.join(outDir, "github", `${channel}-mac.json`) : path.join(outDir, `${channel}-mac.json`)
await (<any>outputJson)(updateInfoFile, <VersionInfo>{
version: version,
url: computeDownloadUrl(publishConfig, packager.generateName2("zip", "mac", isGitHub), version, {os: Platform.MAC.buildConfigurationKey, arch: Arch[Arch.x64]})
releaseDate: new Date().toISOString(),
url: computeDownloadUrl(publishConfig, packager.generateName2("zip", "mac", isGitHub), version, {
os: Platform.MAC.buildConfigurationKey,
arch: Arch[Arch.x64]
}),
}, {spaces: 2})

packager.info.dispatchArtifactCreated({
Expand All @@ -211,6 +215,7 @@ async function writeUpdateInfo(event: ArtifactCreated, _publishConfigs: Array<Pu
const updateInfoFile = path.join(outDir, `${channel}.yml`)
await writeFile(updateInfoFile, safeDump(<UpdateInfo>{
version: version,
releaseDate: new Date().toISOString(),
githubArtifactName: githubArtifactName,
path: path.basename(event.file!),
sha2: sha2,
Expand Down Expand Up @@ -282,7 +287,6 @@ function expandPattern(pattern: string, macros: Macros): string {
.replace(/\$\{arch}/g, macros.arch)
}


export function getPublishConfigs(packager: PlatformPackager<any>, targetSpecificOptions: PlatformSpecificBuildOptions | null | undefined, errorIfCannot: boolean): Promise<Array<PublishConfiguration>> | null {
let publishers

Expand Down
4 changes: 2 additions & 2 deletions packages/electron-updater/src/AppUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export abstract class AppUpdater extends EventEmitter {
if (this.logger != null) {
this.logger.info(`Update for version ${currentVersionString} is not available (latest version: ${versionInfo.version})`)
}
this.emit("update-not-available")
this.emit("update-not-available", versionInfo)
return {
versionInfo: versionInfo,
}
Expand All @@ -193,7 +193,7 @@ export abstract class AppUpdater extends EventEmitter {
if (this.logger != null) {
this.logger.info(`Found version ${versionInfo.version} (url: ${fileInfo.url})`)
}
this.emit("update-available")
this.emit("update-available", versionInfo)
}

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/electron-updater/src/MacUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ export class MacUpdater extends AppUpdater {
this.emit("error", it)
})
this.nativeUpdater.on("update-downloaded", () => {
const version = this.versionInfo!.version
if (this.logger != null) {
this.logger.info(`New version ${version} has been downloaded`)
this.logger.info(`New version ${this.versionInfo!.version} has been downloaded`)
}
this.emit("update-downloaded", this.versionInfo)
})
Expand Down
5 changes: 2 additions & 3 deletions packages/electron-updater/src/NsisUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ export class NsisUpdater extends AppUpdater {
throw e
}

const version = this.versionInfo!.version
if (logger != null) {
logger.info(`New version ${version} has been downloaded to ${tempFile}`)
logger.info(`New version ${this.versionInfo!.version} has been downloaded to ${tempFile}`)
}

this.setupPath = tempFile
this.addQuitHandler()
this.emit("update-downloaded", this.versionInfo, null, version)
this.emit("update-downloaded", this.versionInfo)
return tempFile
}

Expand Down
8 changes: 3 additions & 5 deletions packages/electron-updater/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { RequestHeaders } from "electron-builder-http"
import { ProgressInfo } from "electron-builder-http/out/ProgressCallbackTransform"

export interface FileInfo {
name: string

url: string

sha2?: string
readonly name: string
readonly url: string
readonly sha2?: string
}

export abstract class Provider<T extends VersionInfo> {
Expand Down
1 change: 1 addition & 0 deletions test/out/mac/__snapshots__/macPackagerTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Array [

exports[`test one-package 3`] = `
Object {
"releaseDate": "1970-01-01T00:00:00.000Z",
"url": "https://develar.s3.amazonaws.com/test/mac/x64/Test%20App%20%C3%9FW-1.1.0-mac.zip",
"version": "1.1.0",
}
Expand Down
7 changes: 7 additions & 0 deletions test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,4 +563,11 @@ export function allPlatforms(dist = true): PackagerOptions {
return {
targets: getPossiblePlatforms(dist ? null : DIR_TARGET),
}
}

export function convertUpdateInfo(info: any) {
if (info.releaseDate != null) {
info.releaseDate = "1970-01-01T00:00:00.000Z"
}
return info
}
10 changes: 5 additions & 5 deletions test/src/mac/macPackagerTest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { assertPack, platform, app, appThrows } from "../helpers/packTester"
import { Platform, createTargets } from "electron-builder"
import { readJson } from "fs-extra-p"
import { DIR_TARGET } from "electron-builder/out/targets/targetFactory"
import { createTargets, Platform } from "electron-builder"
import { copyFile } from "electron-builder-util/out/fs"
import { DIR_TARGET } from "electron-builder/out/targets/targetFactory"
import { readJson } from "fs-extra-p"
import * as path from "path"
import { assertThat } from "../helpers/fileAssert"
import { app, appThrows, assertPack, convertUpdateInfo, platform } from "../helpers/packTester"

test.ifMac("two-package", () => assertPack("test-app", {targets: createTargets([Platform.MAC], null, "all")}, {signed: true, useTempDir: true}))

Expand Down Expand Up @@ -39,7 +39,7 @@ test.ifMac("one-package", app({
await assertThat(path.join(appDir, "Contents", "Resources", "foo.icns")).isFile()
},
packed: async context => {
expect(await readJson(path.join(context.outDir, "latest-mac.json"))).toMatchSnapshot()
expect(convertUpdateInfo(await readJson(path.join(context.outDir, "latest-mac.json")))).toMatchSnapshot()
},
}))

Expand Down
20 changes: 12 additions & 8 deletions test/src/windows/nsisTest.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Platform, Arch } from "electron-builder"
import { assertPack, app, copyTestAsset, modifyPackageJson, appThrows } from "../helpers/packTester"
import { outputFile, readFile } from "fs-extra-p"
import * as path from "path"
import BluebirdPromise from "bluebird-lst-c"
import { assertThat } from "../helpers/fileAssert"
import { extractFile } from "asar-electron-builder"
import BluebirdPromise from "bluebird-lst-c"
import { Arch, Platform } from "electron-builder"
import { archFromString } from "electron-builder-core"
import { walk } from "electron-builder-util/out/fs"
import { WineManager, diff } from "../helpers/wine"
import { outputFile, readFile } from "fs-extra-p"
import { safeLoad } from "js-yaml"
import { archFromString } from "electron-builder-core"
import * as path from "path"
import { assertThat } from "../helpers/fileAssert"
import { app, appThrows, assertPack, copyTestAsset, modifyPackageJson } from "../helpers/packTester"
import { diff, WineManager } from "../helpers/wine"

const nsisTarget = Platform.WINDOWS.createTarget(["nsis"])

Expand Down Expand Up @@ -64,7 +64,9 @@ test.ifDevOrLinuxCi("perMachine, no run after finish", app({
expect(safeLoad(await readFile(path.join(context.getResources(Platform.WINDOWS, Arch.ia32), "app-update.yml"), "utf-8"))).toMatchSnapshot()
const updateInfo = safeLoad(await readFile(path.join(context.outDir, "latest.yml"), "utf-8"))
expect(updateInfo.sha2).not.toEqual("")
expect(updateInfo.releaseDate).not.toEqual("")
delete updateInfo.sha2
delete updateInfo.releaseDate
expect(updateInfo).toMatchSnapshot()
await doTest(context.outDir, false)
},
Expand Down Expand Up @@ -183,7 +185,9 @@ test("allowToChangeInstallationDirectory", app({
expect(safeLoad(await readFile(path.join(context.getResources(Platform.WINDOWS, archFromString(process.arch)), "app-update.yml"), "utf-8"))).toMatchSnapshot()
const updateInfo = safeLoad(await readFile(path.join(context.outDir, "latest.yml"), "utf-8"))
expect(updateInfo.sha2).not.toEqual("")
expect(updateInfo.releaseDate).not.toEqual("")
delete updateInfo.sha2
delete updateInfo.releaseDate
expect(updateInfo).toMatchSnapshot()
await doTest(context.outDir, false)
}
Expand Down

0 comments on commit 45c93bf

Please sign in to comment.