Skip to content

Commit a457d0d

Browse files
committed
fix(electron-auto-updater): load default provider only if custom was not set
1 parent 4faa3fb commit a457d0d

File tree

3 files changed

+9
-34
lines changed

3 files changed

+9
-34
lines changed

nsis-auto-updater/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "electron-auto-updater",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"description": "NSIS Auto Updater",
55
"main": "out/nsis-auto-updater/src/main.js",
66
"author": "Vladimir Krivosheev",

nsis-auto-updater/src/NsisUpdater.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ export class NsisUpdater extends EventEmitter {
3030

3131
this.app = (<any>global).__test_app || require("electron").app
3232

33-
if (options == null) {
34-
this.clientPromise = this.loadUpdateConfig()
35-
}
36-
else {
33+
if (options != null) {
3734
this.setFeedURL(options)
3835
}
3936
}
@@ -47,15 +44,11 @@ export class NsisUpdater extends EventEmitter {
4744
}
4845

4946
async checkForUpdates(): Promise<UpdateCheckResult> {
50-
if (this.clientPromise == null) {
51-
const message = "Update URL is not set"
52-
const error = new Error(message)
53-
this.emit("error", error, message)
54-
throw error
55-
}
56-
5747
this.emit("checking-for-update")
5848
try {
49+
if (this.clientPromise == null) {
50+
this.clientPromise = NsisUpdater.loadUpdateConfig()
51+
}
5952
return await this.doCheckForUpdates()
6053
}
6154
catch (e) {
@@ -157,14 +150,8 @@ export class NsisUpdater extends EventEmitter {
157150
return true
158151
}
159152

160-
async loadUpdateConfig() {
161-
try {
162-
return createClient(safeLoad(await readFile(path.join((<any>global).__test_resourcesPath || (<any>process).resourcesPath, "app-update.yml"), "utf-8")))
163-
}
164-
catch (e) {
165-
this.emit("error", e, (e.stack || e).toString())
166-
throw e
167-
}
153+
private static async loadUpdateConfig() {
154+
return createClient(safeLoad(await readFile(path.join((<any>global).__test_resourcesPath || (<any>process).resourcesPath, "app-update.yml"), "utf-8")))
168155
}
169156
}
170157

test/src/nsisUpdaterTest.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { TmpDir } from "out/util/tmp"
55
import { outputFile } from "fs-extra-p"
66
import { safeDump } from "js-yaml"
77
import { GenericServerOptions, GithubOptions } from "out/options/publishOptions"
8-
import BluebirdPromise from "bluebird-lst-c"
98

109
if (process.env.ELECTRON_BUILDER_OFFLINE === "true") {
1110
fit("Skip ArtifactPublisherTest suite — ELECTRON_BUILDER_OFFLINE is defined", () => {
@@ -134,24 +133,13 @@ test("test error", async () => {
134133
const updater: NsisUpdater = new NsisUpdaterClass()
135134

136135
const actualEvents: Array<string> = []
137-
const expectedEvents = ["checking-for-update", "error"]
136+
const expectedEvents = ["checking-for-update", "error", "error"]
138137
for (const eventName of expectedEvents) {
139138
updater.addListener(eventName, () => {
140139
actualEvents.push(eventName)
141140
})
142141
}
143142

144143
await assertThat(updater.checkForUpdates()).throws("Path must be a string. Received undefined")
145-
await new BluebirdPromise(function (resolve, reject) {
146-
setTimeout(() => {
147-
try {
148-
expect(actualEvents).toEqual(expectedEvents)
149-
}
150-
catch (e) {
151-
reject(e)
152-
}
153-
154-
resolve()
155-
}, 500)
156-
})
144+
expect(actualEvents).toEqual(expectedEvents)
157145
})

0 commit comments

Comments
 (0)