Skip to content

Commit eb6a453

Browse files
committed
feat(electron-updater): NSIS autoUpdater.setFeedURL throws error
Closes #1105
1 parent 3dd87da commit eb6a453

File tree

3 files changed

+132
-128
lines changed

3 files changed

+132
-128
lines changed

docs/Auto Update.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ The `autoUpdater` object has the following methods:
9898
9999
### `autoUpdater.setFeedURL(options)`
100100
101-
* `options` GenericServerOptions | BintrayOptions | GithubOptions — if you want to override configuration in the `app-update.yml`.
101+
* `options` GenericServerOptions | BintrayOptions | GithubOptions | string — if you want to override configuration in the `app-update.yml`.
102102
103-
Sets the `options`. Windows-only for now. On macOS please refer [electron setFeedURL reference](https://github.com/electron/electron/blob/master/docs/api/auto-updater.md#autoupdatersetfeedurlurl-requestheaders).
103+
Sets the `options`. If value is `string`, `GenericServerOptions` will be set with value as `url`.
104104
105105
### `autoUpdater.checkForUpdates(): Promise<UpdateCheckResult>`
106106
107-
Asks the server whether there is an update. On macOS you must call `setFeedURL` before using this API.
107+
Asks the server whether there is an update.
108108
109109
### `autoUpdater.quitAndInstall()`
110110

packages/electron-updater/src/AppUpdater.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,16 @@ export abstract class AppUpdater extends EventEmitter {
8989
return "Deprecated. Do not use it."
9090
}
9191

92-
setFeedURL(value: PublishConfiguration | BintrayOptions | GithubOptions | GenericServerOptions) {
93-
this.clientPromise = BluebirdPromise.resolve(createClient(value))
92+
setFeedURL(value: PublishConfiguration | BintrayOptions | GithubOptions | GenericServerOptions | string) {
93+
// https://github.com/electron-userland/electron-builder/issues/1105
94+
let client: Provider<any>
95+
if (typeof value === "string") {
96+
client = new GenericProvider({provider: "generic", url: value})
97+
}
98+
else {
99+
client = createClient(value)
100+
}
101+
this.clientPromise = BluebirdPromise.resolve(client)
94102
}
95103

96104
checkForUpdates(): Promise<UpdateCheckResult> {
@@ -118,7 +126,7 @@ export abstract class AppUpdater extends EventEmitter {
118126
this.emit("checking-for-update")
119127
try {
120128
if (this.clientPromise == null) {
121-
this.clientPromise = loadUpdateConfig()
129+
this.clientPromise = loadUpdateConfig().then(it => createClient(it))
122130
}
123131
return await this.doCheckForUpdates()
124132
}
@@ -205,7 +213,7 @@ export abstract class AppUpdater extends EventEmitter {
205213
}
206214

207215
async function loadUpdateConfig() {
208-
return createClient(safeLoad(await readFile(path.join((<any>global).__test_resourcesPath || (<any>process).resourcesPath, "app-update.yml"), "utf-8")))
216+
return safeLoad(await readFile(path.join((<any>global).__test_resourcesPath || (<any>process).resourcesPath, "app-update.yml"), "utf-8"))
209217
}
210218

211219
function createClient(data: string | PublishConfiguration | BintrayOptions | GithubOptions) {

0 commit comments

Comments
 (0)