Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added electron 3(Node 10) support to nisis updater #3371

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/electron-updater/src/AppImageUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class AppImageUpdater extends BaseUpdater {
})
}

protected doInstall(installerPath: string, isSilent: boolean, isRunAfter: boolean): boolean {
protected async doInstall(installerPath: string, isSilent: boolean, isRunAfter: boolean): Promise<boolean> {
const appImageFile = process.env.APPIMAGE!!
if (appImageFile == null) {
throw newError("APPIMAGE env is not defined", "ERR_UPDATER_OLD_FILE_NOT_FOUND")
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-updater/src/BaseUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export abstract class BaseUpdater extends AppUpdater {
})
}

protected abstract doInstall(installerPath: string, isSilent: boolean, isRunAfter: boolean): boolean
protected abstract doInstall(installerPath: string, isSilent: boolean, isRunAfter: boolean): Promise<boolean>

protected async install(isSilent: boolean, isRunAfter: boolean): Promise<boolean> {
if (this.quitAndInstallCalled) {
Expand All @@ -54,7 +54,7 @@ export abstract class BaseUpdater extends AppUpdater {

try {
this._logger.info(`Install: isSilent: ${isSilent}, isRunAfter: ${isRunAfter}`)
return this.doInstall(installerPath, isSilent, isRunAfter)
return await this.doInstall(installerPath, isSilent, isRunAfter)
}
catch (e) {
this.dispatchError(e)
Expand Down
33 changes: 28 additions & 5 deletions packages/electron-updater/src/NsisUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class NsisUpdater extends BaseUpdater {
return await verifySignature(Array.isArray(publisherName) ? publisherName : [publisherName], tempUpdateFile, this._logger)
}

protected doInstall(installerPath: string, isSilent: boolean, isForceRunAfter: boolean): boolean {
protected async doInstall(installerPath: string, isSilent: boolean, isForceRunAfter: boolean): Promise<boolean> {
const args = ["--updated"]
if (isSilent) {
args.push("/S")
Expand All @@ -109,17 +109,15 @@ export class NsisUpdater extends BaseUpdater {
}

try {
spawn(installerPath, args, spawnOptions)
.unref()
await this._spawn(installerPath, args, spawnOptions)
}
catch (e) {
// yes, such errors dispatched not as error event
// https://github.com/electron-userland/electron-builder/issues/1129
if ((e as any).code === "UNKNOWN" || (e as any).code === "EACCES") { // Node 8 sends errors: https://nodejs.org/dist/latest-v8.x/docs/api/errors.html#errors_common_system_errors
this._logger.info("Access denied or UNKNOWN error code on spawn, will be executed again using elevate")
try {
spawn(path.join(process.resourcesPath!, "elevate.exe"), [installerPath].concat(args), spawnOptions)
.unref()
await this._spawn(path.join(process.resourcesPath!, "elevate.exe"), [installerPath].concat(args), spawnOptions)
}
catch (e) {
this.dispatchError(e)
Expand All @@ -133,6 +131,31 @@ export class NsisUpdater extends BaseUpdater {
return true
}

/**
* This handles both node 8 and node 10 way of emitting error when spawing a process
* - node 8: Throws the error
* - node 10: Emit the error(Need to listen with on)
*/
private async _spawn(exe: string, args: Array<string>, options: any) {
return new Promise((resolve, reject) => {

try {
const process = spawn(exe, args, options)
process.on("error", error => {
reject(error)
})
process.unref()

if (process.pid !== undefined) {
resolve(true)
}
} catch (error) {
reject(error)
}
})

}

// private downloadBlockMap(provider: Provider<any>) {
// await provider.getBytes(newBlockMapUrl, cancellationToken)
// }
Expand Down