Skip to content

Commit

Permalink
fix(electron-updater): Added electron 3(Node 10) support to nsis updater
Browse files Browse the repository at this point in the history
Close #3371
  • Loading branch information
timotheeguerin authored and develar committed Oct 25, 2018
1 parent a6c5bc4 commit 78a65d2
Show file tree
Hide file tree
Showing 10 changed files with 1,361 additions and 253 deletions.
28 changes: 14 additions & 14 deletions package.json
Expand Up @@ -37,16 +37,16 @@
"bluebird-lst": "^1.0.5",
"chalk": "^2.4.1",
"chromium-pickle-js": "^0.2.0",
"debug": "^3.1.0",
"debug": "^4.1.0",
"ejs": "^2.6.1",
"electron-is-dev": "^0.3.0",
"electron-osx-sign": "0.4.10",
"electron-osx-sign": "0.4.11",
"env-paths": "^1.0.0",
"fs-extra-p": "^4.6.1",
"hosted-git-info": "^2.7.1",
"iconv-lite": "^0.4.24",
"ini": "^1.3.5",
"is-ci": "^1.2.0",
"is-ci": "^1.2.1",
"isbinaryfile": "^3.0.3",
"js-yaml": "^3.12.0",
"lazy-val": "^1.0.3",
Expand All @@ -59,7 +59,7 @@
"read-config-file": "3.1.2",
"sanitize-filename": "^1.6.1",
"sax": "^1.2.4",
"semver": "^5.5.1",
"semver": "^5.6.0",
"source-map-support": "^0.5.9",
"stat-mode": "^0.2.2",
"sumchecker": "^2.0.2",
Expand All @@ -69,14 +69,14 @@
"yargs": "^12.0.2"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-decorators": "^7.0.0",
"@babel/core": "^7.1.2",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-decorators": "^7.1.2",
"@babel/plugin-proposal-do-expressions": "^7.0.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-proposal-function-bind": "^7.0.0",
"@babel/plugin-proposal-function-sent": "^7.0.0",
"@babel/plugin-proposal-function-sent": "^7.1.0",
"@babel/plugin-proposal-json-strings": "^7.0.0",
"@babel/plugin-proposal-logical-assignment-operators": "^7.0.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
Expand All @@ -86,13 +86,13 @@
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-import-meta": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"@babel/preset-react": "^7.0.0",
"@types/debug": "^0.0.30",
"@types/debug": "^0.0.31",
"@types/ejs": "^2.6.0",
"@types/electron-is-dev": "^0.3.0",
"@types/ini": "^1.3.29",
"@types/jest": "^23.3.2",
"@types/jest": "^23.3.7",
"@types/js-yaml": "^3.11.2",
"@types/lodash.isequal": "^4.5.3",
"@types/node-emoji": "^1.8.0",
Expand All @@ -111,15 +111,15 @@
"electron-builder-tslint-config": "^1.1.0",
"env-paths": "^1.0.0",
"globby": "^8.0.1",
"jest-cli": "^23.5.0",
"jest-junit": "^5.1.0",
"jest-cli": "^23.6.0",
"jest-junit": "^5.2.0",
"jsdoc-to-markdown": "^4.0.1",
"path-sort": "^0.1.0",
"sumchecker": "^2.0.2",
"ts-babel": "6.0.2",
"ts-jsdoc": "^3.0.1",
"tslint": "^5.11.0",
"typescript": "^3.0.3",
"typescript": "^3.1.3",
"whitespace": "^2.1.0",
"worker-farm": "^1.6.0"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/app-builder-lib/package.json
Expand Up @@ -48,20 +48,20 @@
"chromium-pickle-js": "^0.2.0",
"builder-util-runtime": "0.0.0-semantic-release",
"builder-util": "0.0.0-semantic-release",
"electron-osx-sign": "0.4.10",
"electron-osx-sign": "0.4.11",
"electron-publish": "0.0.0-semantic-release",
"fs-extra-p": "^4.6.1",
"hosted-git-info": "^2.7.1",
"is-ci": "^1.2.0",
"is-ci": "^1.2.1",
"isbinaryfile": "^3.0.3",
"js-yaml": "^3.12.0",
"read-config-file": "3.1.2",
"minimatch": "^3.0.4",
"normalize-package-data": "^2.4.0",
"plist": "^3.0.1",
"sanitize-filename": "^1.6.1",
"semver": "^5.5.1",
"debug": "^3.1.0",
"semver": "^5.6.0",
"debug": "^4.1.0",
"lazy-val": "^1.0.3",
"temp-file": "^3.1.3",
"ejs": "^2.6.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/builder-util-runtime/package.json
Expand Up @@ -14,7 +14,7 @@
"node": ">=6.0.0"
},
"dependencies": {
"debug": "^3.1.0",
"debug": "^4.1.0",
"fs-extra-p": "^4.6.1",
"bluebird-lst": "^1.0.5",
"sax": "^1.2.4"
Expand Down
6 changes: 3 additions & 3 deletions packages/builder-util/package.json
Expand Up @@ -14,15 +14,15 @@
"app-builder-bin": "2.1.3",
"temp-file": "^3.1.3",
"fs-extra-p": "^4.6.1",
"is-ci": "^1.2.0",
"is-ci": "^1.2.1",
"stat-mode": "^0.2.2",
"bluebird-lst": "^1.0.5",
"chalk": "^2.4.1",
"debug": "^3.1.0",
"debug": "^4.1.0",
"builder-util-runtime": "^0.0.0-semantic-release",
"source-map-support": "^0.5.9",
"7zip-bin": "~4.0.2",
"semver": "^5.5.1",
"semver": "^5.6.0",
"lazy-val": "^1.0.3",
"js-yaml": "^3.12.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/package.json
Expand Up @@ -51,7 +51,7 @@
"builder-util-runtime": "0.0.0-semantic-release",
"builder-util": "0.0.0-semantic-release",
"fs-extra-p": "^4.6.1",
"is-ci": "^1.2.0",
"is-ci": "^1.2.1",
"read-config-file": "3.1.2",
"sanitize-filename": "^1.6.1",
"update-notifier": "^2.5.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-updater/package.json
Expand Up @@ -16,7 +16,7 @@
"bluebird-lst": "^1.0.5",
"fs-extra-p": "^4.6.1",
"js-yaml": "^3.12.0",
"semver": "^5.5.1",
"semver": "^5.6.0",
"source-map-support": "^0.5.9",
"builder-util-runtime": "~0.0.0-semantic-release",
"electron-is-dev": "^0.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-updater/src/AppImageUpdater.ts
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
Expand Up @@ -35,7 +35,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 @@ -56,7 +56,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
34 changes: 26 additions & 8 deletions packages/electron-updater/src/NsisUpdater.ts
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,9 +131,29 @@ export class NsisUpdater extends BaseUpdater {
return true
}

// private downloadBlockMap(provider: Provider<any>) {
// await provider.getBytes(newBlockMapUrl, cancellationToken)
// }
/**
* 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 async differentialDownloadInstaller(fileInfo: ResolvedUpdateFileInfo, downloadUpdateOptions: DownloadUpdateOptions, installerPath: string, requestHeaders: OutgoingHttpHeaders, provider: Provider<any>) {
try {
Expand Down

0 comments on commit 78a65d2

Please sign in to comment.