Skip to content

Commit 5e09db4

Browse files
MariaDimadevelar
authored andcommitted
fix(electron-updater): Auto update does not work on machines with Powershell version < 3
Close #1732
1 parent af77da8 commit 5e09db4

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

packages/electron-updater/src/NsisUpdater.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import BluebirdPromise from "bluebird-lst"
2-
import { execFile, spawn } from "child_process"
2+
import { execFile, execFileSync, spawn } from "child_process"
33
import { CancellationError, CancellationToken, DownloadOptions } from "electron-builder-http"
44
import { PublishConfiguration } from "electron-builder-http/out/publishOptions"
55
import { parseDn } from "electron-builder-http/out/rfc2253Parser"
@@ -94,14 +94,25 @@ export class NsisUpdater extends AppUpdater {
9494

9595
return await new BluebirdPromise<string | null>((resolve, reject) => {
9696
execFile("powershell.exe", [`Get-AuthenticodeSignature '${tempUpdateFile}' | ConvertTo-Json -Compress`], {maxBuffer: 4 * 1024000, timeout: 60 * 1000}, (error, stdout, stderr) => {
97-
if (error != null) {
98-
reject(error)
99-
return
100-
}
97+
if (error != null || stderr) {
98+
try {
99+
execFileSync("powershell.exe", ["ConvertTo-Json test"], {timeout: 10 * 1000})
100+
}
101+
catch (testError) {
102+
this._logger.warn(`Cannot execute ConvertTo-Json: ${testError.message}. Ignoring signature validation due to unsupported powershell version. Please upgrade to powershell 3 or higher.`)
103+
resolve(null)
104+
return
105+
}
101106

102-
if (stderr) {
103-
reject(new Error(`Cannot execute Get-AuthenticodeSignature: ${stderr}`))
104-
return
107+
if (error != null) {
108+
reject(error)
109+
return
110+
}
111+
112+
if (stderr) {
113+
reject(new Error(`Cannot execute Get-AuthenticodeSignature: ${stderr}`))
114+
return
115+
}
105116
}
106117

107118
const data = JSON.parse(stdout)

0 commit comments

Comments
 (0)