Skip to content

Commit

Permalink
fix(nsis): improve Windows installer task kill process (related to ch…
Browse files Browse the repository at this point in the history
…ild processes)

Close #2894
  • Loading branch information
develar committed Jul 31, 2019
1 parent 371296a commit 39e6783
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 43 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"normalize-package-data": "^2.5.0",
"pako": "^1.0.10",
"read-config-file": "5.0.0",
"sanitize-filename": "^1.6.1",
"sanitize-filename": "^1.6.2",
"sax": "^1.2.4",
"semver": "^6.3.0",
"source-map-support": "^0.5.12",
Expand Down Expand Up @@ -91,15 +91,15 @@
"@types/ejs": "^2.6.3",
"@types/fs-extra": "^8.0.0",
"@types/ini": "^1.3.30",
"@types/jest": "^24.0.15",
"@types/jest": "^24.0.16",
"@types/js-yaml": "^3.12.1",
"@types/lodash.isequal": "^4.5.5",
"@types/node-emoji": "^1.8.1",
"@types/sanitize-filename": "^1.1.28",
"@types/sax": "^1.2.0",
"@types/source-map-support": "^0.5.0",
"@types/stat-mode": "^0.2.0",
"@types/yargs": "^13.0.0",
"@types/yargs": "^13.0.1",
"babel-core": "^7.0.0-bridge.0",
"babel-preset-jest": "^24.6.0",
"babel-preset-ts-node8": "~4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"read-config-file": "5.0.0",
"minimatch": "^3.0.4",
"normalize-package-data": "^2.5.0",
"sanitize-filename": "^1.6.1",
"sanitize-filename": "^1.6.2",
"@develar/schema-utils": "~2.1.0",
"semver": "^6.3.0",
"debug": "^4.1.1",
Expand Down
14 changes: 10 additions & 4 deletions packages/app-builder-lib/src/targets/nsis/NsisTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import BluebirdPromise from "bluebird-lst"
import { executeAppBuilder, Arch, asArray, AsyncTaskManager, getPlatformIconFileName, InvalidConfigurationError, log, spawnAndWrite, use, exec } from "builder-util"
import { PackageFileInfo, UUID, CURRENT_APP_PACKAGE_FILE_NAME, CURRENT_APP_INSTALLER_FILE_NAME } from "builder-util-runtime"
import { getBinFromUrl } from "../../binDownload"
import { statOrNull, walk } from "builder-util/out/fs"
import { statOrNull, walk, exists } from "builder-util/out/fs"
import { hashFile } from "../../util/hash"
import _debug from "debug"
import { readFile, stat, unlink } from "fs-extra"
Expand Down Expand Up @@ -316,16 +316,22 @@ export class NsisTarget extends Target {

// https://github.com/electron-userland/electron-builder/issues/2103
// it is more safe and reliable to write uninstaller to our out dir
const uninstallerPath = path.join(this.outDir, `.__uninstaller-${this.name}-${this.packager.appInfo.sanitizedName}.exe`)
const uninstallerPath = path.join(this.outDir, `__uninstaller-${this.name}-${this.packager.appInfo.sanitizedName}.exe`)
const isWin = process.platform === "win32"
defines.BUILD_UNINSTALLER = null
defines.UNINSTALLER_OUT_FILE = isWin ? uninstallerPath : path.win32.join("Z:", uninstallerPath)
await this.executeMakensis(defines, commands, sharedHeader + await this.computeFinalScript(script, false))

// http://forums.winamp.com/showthread.php?p=3078545
//
if (await isMacOsCatalina()) {
if (isMacOsCatalina()) {
(await packager.vm.value).exec(installerPath, [])

// Parallels VM can exit after command execution, but NSIS continue to be running
let i = 0
while (!(await exists(uninstallerPath)) && i++ < 100) {
// noinspection JSUnusedLocalSymbols
await new Promise((resolve, _reject) => setTimeout(resolve, 300))
}
}
else {
await execWine(installerPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
${if} $3 != "${APP_EXECUTABLE_FILENAME}"
${if} ${isUpdated}
# allow app to exit without explicit kill
Sleep 100
Sleep 300
${endIf}

${nsProcess::FindProcess} "${APP_EXECUTABLE_FILENAME}" $R0
Expand All @@ -58,23 +58,20 @@
DetailPrint `Closing running "${PRODUCT_NAME}"...`

# https://github.com/electron-userland/electron-builder/issues/2516#issuecomment-372009092
nsExec::Exec `taskkill /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"` $R0
nsExec::Exec `taskkill /t /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"` $R0
# to ensure that files are not "in-use"
Sleep 100
Sleep 300

${nsProcess::FindProcess} "${APP_EXECUTABLE_FILENAME}" $R0
${if} $R0 == 0
# wait to give a chance to exit gracefully
Sleep 1000
# do not use /t tree kill - app was killed softly already
nsExec::Exec `taskkill /f /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"` $R0
nsExec::Exec `taskkill /f /t /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"` $R0
${If} $R0 != 0
DetailPrint `Waiting for "${PRODUCT_NAME}" to close (taskkill exit code $R0).`
Sleep 2000
${endIf}
${endIf}
${endIf}
${endIf}

${nsProcess::Unload}
!macroend
2 changes: 1 addition & 1 deletion packages/dmg-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"iconv-lite": "^0.5.0",
"js-yaml": "^3.13.1",
"app-builder-lib": "~0.0.0-semantic-release",
"sanitize-filename": "^1.6.1"
"sanitize-filename": "^1.6.2"
},
"typings": "./out/dmg.d.ts"
}
2 changes: 1 addition & 1 deletion packages/electron-builder-squirrel-windows/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"bluebird-lst": "^1.0.9",
"fs-extra": "^8.1.0",
"archiver": "^3.0.3",
"sanitize-filename": "^1.6.1"
"sanitize-filename": "^1.6.2"
},
"optionalDependencies": {
"7zip-bin": "~4.0.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"fs-extra": "^8.1.0",
"is-ci": "^2.0.0",
"read-config-file": "5.0.0",
"sanitize-filename": "^1.6.1",
"sanitize-filename": "^1.6.2",
"update-notifier": "^3.0.1",
"yargs": "^13.3.0",
"lazy-val": "^1.0.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ Object {
},
},
Object {
"arch": "ia32",
"arch": "x64",
"file": "Test App ßW Setup 1.1.0.exe",
"safeArtifactName": "TestApp-Setup-1.1.0.exe",
"updateInfo": Object {
Expand Down
6 changes: 3 additions & 3 deletions test/src/windows/oneClickInstallerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { checkHelpers, doTest, expectUpdateMetadata } from "../helpers/winHelper
const nsisTarget = Platform.WINDOWS.createTarget(["nsis"])

test("one-click", app({
targets: Platform.WINDOWS.createTarget(["nsis"], Arch.ia32),
targets: Platform.WINDOWS.createTarget(["nsis"], Arch.x64),
config: {
publish: {
provider: "bintray",
Expand All @@ -23,9 +23,9 @@ test("one-click", app({
}, {
signedWin: true,
packed: async context => {
await checkHelpers(context.getResources(Platform.WINDOWS, Arch.ia32), false)
await checkHelpers(context.getResources(Platform.WINDOWS, Arch.x64), false)
await doTest(context.outDir, true, "TestApp Setup", "TestApp", null, false)
await expectUpdateMetadata(context, Arch.ia32, true)
await expectUpdateMetadata(context, Arch.x64, true)
}
}))

Expand Down
42 changes: 21 additions & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1211,10 +1211,10 @@
resolved "https://registry.npmjs.org/@types/jest-diff/-/jest-diff-20.0.1.tgz#35cc15b9c4f30a18ef21852e255fdb02f6d59b89"
integrity sha512-yALhelO3i0hqZwhjtcr6dYyaLoCHbAMshwtj6cGxTvHZAKXHsYGdff6E8EPw3xLKY0ELUTQ69Q1rQiJENnccMA==

"@types/jest@^24.0.15":
version "24.0.15"
resolved "https://registry.npmjs.org/@types/jest/-/jest-24.0.15.tgz#6c42d5af7fe3b44ffff7cc65de7bf741e8fa427f"
integrity sha512-MU1HIvWUme74stAoc3mgAi+aMlgKOudgEvQDIm1v4RkrDudBh1T+NFp5sftpBAdXdx1J0PbdpJ+M2EsSOi1djA==
"@types/jest@^24.0.16":
version "24.0.16"
resolved "https://registry.npmjs.org/@types/jest/-/jest-24.0.16.tgz#8d3e406ec0f0dc1688d6711af3062ff9bd428066"
integrity sha512-JrAiyV+PPGKZzw6uxbI761cHZ0G7QMOHXPhtSpcl08rZH6CswXaaejckn3goFKmF7M3nzEoJ0lwYCbqLMmjziQ==
dependencies:
"@types/jest-diff" "*"

Expand Down Expand Up @@ -1294,10 +1294,10 @@
resolved "https://registry.npmjs.org/@types/yargs/-/yargs-12.0.12.tgz#45dd1d0638e8c8f153e87d296907659296873916"
integrity sha512-SOhuU4wNBxhhTHxYaiG5NY4HBhDIDnJF60GU+2LqHAdKKer86//e4yg69aENCtQ04n0ovz+tq2YPME5t5yp4pw==

"@types/yargs@^13.0.0":
version "13.0.0"
resolved "https://registry.npmjs.org/@types/yargs/-/yargs-13.0.0.tgz#d2acb3bec0047d8f648ebacdab6b928a900c42c4"
integrity sha512-hY0o+kcz9M6kH32NUeb6VURghqMuCVkiUx+8Btsqhj4Hhov/hVGUx9DmBJeIkzlp1uAQK4wngQBCjqWdUUkFyA==
"@types/yargs@^13.0.1":
version "13.0.1"
resolved "https://registry.npmjs.org/@types/yargs/-/yargs-13.0.1.tgz#a45b3c9faadd7adfdb40646d14a7f6b70f4e8233"
integrity sha512-7X+FaCpRQ1scFQnWUY0TnVuuNaP5ajN45IGmwHVkAbsH1g4txz4hNb6sjJeR/wLaqUdNoInOwLk7oRL5M4zVFA==
dependencies:
"@types/yargs-parser" "*"

Expand Down Expand Up @@ -1828,9 +1828,9 @@ camelcase@^5.0.0, camelcase@^5.3.1:
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==

caniuse-lite@^1.0.30000984:
version "1.0.30000985"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000985.tgz#0eb40f6c8a8c219155cbe43c4975c0efb4a0f77f"
integrity sha512-1ngiwkgqAYPG0JSSUp3PUDGPKKY59EK7NrGGX+VOxaKCNzRbNc7uXMny+c3VJfZxtoK3wSImTvG9T9sXiTw2+w==
version "1.0.30000987"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000987.tgz#bc6b47217afd8226a2b1964635c6bff62cdf5738"
integrity sha512-O3VrjtRMTxoU5Cn5/QSmXeIR1gkVps4j9jqfIm4FLaQ5JzqBlVjMUG1xWnoYFv8N+H3Lp++aa05TekyIbjHL7g==

capture-exit@^2.0.0:
version "2.0.0"
Expand Down Expand Up @@ -2283,9 +2283,9 @@ depcheck@^0.8.3:
yargs "^13.2.2"

deprecate@^1.0.0:
version "1.1.0"
resolved "https://registry.npmjs.org/deprecate/-/deprecate-1.1.0.tgz#bbd069d62b232175b4e8459b2650cd2bad51f4b8"
integrity sha512-b5dDNQYdy2vW9WXUD8+RQlfoxvqztLLhDE+T7Gd37I5E8My7nJkKu6FmhdDeRWJ8B+yjZKuwjCta8pgi8kgSqA==
version "1.1.1"
resolved "https://registry.npmjs.org/deprecate/-/deprecate-1.1.1.tgz#4632e981fc815eeaf00be945a40359c0f8bf9913"
integrity sha512-ZGDXefq1xknT292LnorMY5s8UVU08/WKdzDZCUT6t9JzsiMSP4uzUhgpqugffNVcT5WC6wMBiSQ+LFjlv3v7iQ==

deps-regex@^0.1.4:
version "0.1.4"
Expand Down Expand Up @@ -2400,9 +2400,9 @@ electron-builder-tslint-config@^1.1.0:
integrity sha512-m/oAwS+NYB/b182bGY8C7uj1cDy8XXnHTl5CwD98dng7wE/nZGV2mJD9NyqbFmhJ1kF61wbsYDVx2KLIN5s5tg==

electron-to-chromium@^1.3.191:
version "1.3.200"
resolved "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.200.tgz#78fb858b466269e8eb46d31a52562f00c865127f"
integrity sha512-PUurrpyDA74MuAjJRD+79ss5BqJlU3mdArRbuu4wO/dt6jc3Ic/6BDmFJxkdwbfq39cHf/XKm2vW98XSvut9Dg==
version "1.3.204"
resolved "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.204.tgz#1ea5c6d495bab77995aa135dbcbc1d383dd4e21e"
integrity sha512-T0eXE6hfbtpzRUaI7aHI/HYJ29Ndk84aVSborRAmXfWvBvz2EuB2OWYUxNcUX9d+jtqEIjgZjWMdoxS0hp5j1g==

emoji-regex@^7.0.1:
version "7.0.3"
Expand Down Expand Up @@ -5263,10 +5263,10 @@ sane@^4.0.3:
minimist "^1.1.1"
walker "~1.0.5"

sanitize-filename@^1.6.1:
version "1.6.1"
resolved "https://registry.npmjs.org/sanitize-filename/-/sanitize-filename-1.6.1.tgz#612da1c96473fa02dccda92dcd5b4ab164a6772a"
integrity sha1-YS2hyWRz+gLczaktzVtKsWSmdyo=
sanitize-filename@^1.6.2:
version "1.6.2"
resolved "https://registry.npmjs.org/sanitize-filename/-/sanitize-filename-1.6.2.tgz#01b4fc8809f14e9d22761fe70380fe7f3f902185"
integrity sha512-cmTzND7RMxUB+f7gI+4+KAVHWEg0lfXvQJdko+FXDP5bNbGIdx4KMP5pX6lv5jfT9jSf6OBbjyxjFtZQwYA/ig==
dependencies:
truncate-utf8-bytes "^1.0.0"

Expand Down

0 comments on commit 39e6783

Please sign in to comment.