Skip to content

Commit 5b71f6d

Browse files
committed
fix(nsis): if allowToChangeInstallationDirectory enabled, do not show page if updated
Close #1715
1 parent f545d1e commit 5b71f6d

File tree

11 files changed

+39
-17
lines changed

11 files changed

+39
-17
lines changed

packages/builder-util/src/asyncTaskManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class AsyncTaskManager {
2727

2828
this.tasks.push(promise
2929
.catch(it => {
30-
log.debug({error: it.message}, "async task error")
30+
log.debug({error: it.message || it.toString()}, "async task error")
3131
this.errors.push(it)
3232
return BluebirdPromise.resolve(null)
3333
}))

packages/electron-builder-lib/src/targets/nsis/NsisTarget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export class NsisTarget extends Target {
210210
const sharedHeader = await this.computeCommonInstallerScriptHeader()
211211
const script = isPortable ? await readFile(path.join(nsisTemplatesDir, "portable.nsi"), "utf8") : await this.computeScriptAndSignUninstaller(defines, commands, installerPath, sharedHeader)
212212
await this.executeMakensis(defines, commands, sharedHeader + await this.computeFinalScript(script, true))
213-
await BluebirdPromise.all<any>([packager.sign(installerPath), defines.UNINSTALLER_OUT_FILE == null ? BluebirdPromise.resolve() : unlink(defines.UNINSTALLER_OUT_FILE)])
213+
await Promise.all<any>([packager.sign(installerPath), defines.UNINSTALLER_OUT_FILE == null ? Promise.resolve() : unlink(defines.UNINSTALLER_OUT_FILE)])
214214

215215
const safeArtifactName = isSafeGithubName(installerFilename) ? installerFilename : this.generateGitHubInstallerName()
216216

packages/electron-builder-lib/templates/nsis/assistedInstaller.nsh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
!endif
2222

2323
!ifmacrodef licensePage
24-
!insertmacro licensePageHelper
24+
!insertmacro skipPageIfUpdated
2525
!insertmacro licensePage
2626
!endif
2727

@@ -32,6 +32,7 @@
3232
!ifdef allowToChangeInstallationDirectory
3333
!include StrContains.nsh
3434

35+
!insertmacro skipPageIfUpdated
3536
!insertmacro MUI_PAGE_DIRECTORY
3637

3738
# pageDirectory leave doesn't work (it seems because $INSTDIR is set after custom leave function)

packages/electron-builder-lib/templates/nsis/common.nsh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,17 @@ Name "${PRODUCT_NAME}"
6363
!endif
6464
!macroend
6565

66-
!macro licensePageHelper
67-
Function licensePre
66+
!macro skipPageIfUpdated
67+
!define UniqueID ${__LINE__}
68+
69+
Function skipPageIfUpdated_${UniqueID}
6870
${if} ${isUpdated}
6971
Abort
7072
${endif}
7173
FunctionEnd
7274

73-
!define MUI_PAGE_CUSTOMFUNCTION_PRE licensePre
75+
!define MUI_PAGE_CUSTOMFUNCTION_PRE skipPageIfUpdated_${UniqueID}
76+
!undef UniqueID
7477
!macroend
7578

7679
!macro StartApp
@@ -82,4 +85,17 @@ Name "${PRODUCT_NAME}"
8285
${endif}
8386

8487
${StdUtils.ExecShellAsUser} $0 "$launchLink" "open" "$startAppArgs"
85-
!macroend
88+
!macroend
89+
90+
!ifndef BUILD_UNINSTALLER
91+
Var isTryToKeepShortcuts
92+
93+
!macro setIsTryToKeepShortcuts
94+
StrCpy $isTryToKeepShortcuts "true"
95+
!ifdef allowToChangeInstallationDirectory
96+
${ifNot} ${isUpdated}
97+
StrCpy $isTryToKeepShortcuts "false"
98+
${endIf}
99+
!endif
100+
!macroend
101+
!endif

packages/electron-builder-lib/templates/nsis/include/installer.nsh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,16 @@
4040
StrCpy $0 "/allusers"
4141
${endif}
4242

43-
!ifndef allowToChangeInstallationDirectory
43+
!insertMacro setIsTryToKeepShortcuts
44+
45+
${if} $isTryToKeepShortcuts == "true"
4446
ReadRegStr $R5 SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" KeepShortcuts
4547
# if true, it means that old uninstaller supports --keep-shortcuts flag
4648
${if} $R5 == "true"
4749
${andIf} ${FileExists} "$appExe"
4850
StrCpy $0 "$0 --keep-shortcuts"
4951
${endIf}
50-
!endif
52+
${endIf}
5153

5254
${if} ${isDeleteAppData}
5355
StrCpy $0 "$0 --delete-app-data"

packages/electron-builder-lib/templates/nsis/installSection.nsh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ StrCpy $appExe "$INSTDIR\${APP_EXECUTABLE_FILENAME}"
3636

3737
Var /GLOBAL keepShortcuts
3838
StrCpy $keepShortcuts "false"
39-
!ifndef allowToChangeInstallationDirectory
39+
!insertMacro setIsTryToKeepShortcuts
40+
${if} $isTryToKeepShortcuts == "true"
4041
ReadRegStr $R1 SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" KeepShortcuts
4142

4243
${if} $R1 == "true"
4344
${andIf} ${FileExists} "$appExe"
4445
StrCpy $keepShortcuts "true"
4546
${endIf}
46-
!endif
47+
${endif}
4748

4849
!insertmacro uninstallOldVersion SHELL_CONTEXT
4950
${if} $installMode == "all"

packages/electron-builder-lib/templates/nsis/oneClick.nsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
!ifndef BUILD_UNINSTALLER
22
!ifmacrodef licensePage
3-
!insertmacro licensePageHelper
3+
!insertmacro skipPageIfUpdated
44
!insertmacro licensePage
55
!endif
66
!endif

test/out/mac/__snapshots__/dmgTest.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Object {
2626
exports[`bundleShortVersion 2`] = `
2727
Object {
2828
"AsarIntegrity": "{\\"checksums\\":{\\"app.asar\\":\\"hash\\",\\"electron.asar\\":\\"hash\\"}}",
29-
"BuildMachineOSBuild": "16G29",
29+
"BuildMachineOSBuild": "16G1114",
3030
"CFBundleDisplayName": "BundleShortVersion",
3131
"CFBundleExecutable": "BundleShortVersion",
3232
"CFBundleIconFile": "BundleShortVersion.icns",

test/out/mac/__snapshots__/macArchiveTest.js.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ Array [
137137
"Test App ßW.app/Contents/Frameworks/ReactiveCocoa.framework/ReactiveCocoa",
138138
"Test App ßW.app/Contents/Frameworks/ReactiveCocoa.framework/Resources",
139139
"Test App ßW.app/Contents/Frameworks/ReactiveCocoa.framework/Versions",
140+
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/.DS_Store",
140141
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Headers",
141142
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Modules",
142143
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Resources",
@@ -151,6 +152,7 @@ Array [
151152
"Test App ßW.app/Contents/Frameworks/Mantle.framework/Versions/Current",
152153
"Test App ßW.app/Contents/Frameworks/ReactiveCocoa.framework/Versions/A",
153154
"Test App ßW.app/Contents/Frameworks/ReactiveCocoa.framework/Versions/Current",
155+
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Versions/.DS_Store",
154156
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Versions/A",
155157
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Versions/Current",
156158
"Test App ßW.app/Contents/Frameworks/Test App ßW Helper EH.app/Contents/Info.plist",
@@ -173,6 +175,7 @@ Array [
173175
"Test App ßW.app/Contents/Frameworks/ReactiveCocoa.framework/Versions/A/Modules",
174176
"Test App ßW.app/Contents/Frameworks/ReactiveCocoa.framework/Versions/A/ReactiveCocoa",
175177
"Test App ßW.app/Contents/Frameworks/ReactiveCocoa.framework/Versions/A/Resources",
178+
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Versions/A/.DS_Store",
176179
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Versions/A/Headers",
177180
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Versions/A/Modules",
178181
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Versions/A/Resources",

test/src/mac/dmgTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ test.ifAll.ifMac("retina background as 2 png", () => {
9393
})
9494
})
9595

96-
test.ifMac("no Applications link", () => {
96+
test.ifMac.ifAll("no Applications link", () => {
9797
return assertPack("test-app-one", {
9898
targets: Platform.MAC.createTarget(),
9999
config: {

0 commit comments

Comments
 (0)