Skip to content

Commit

Permalink
fix(nsis): if allowToChangeInstallationDirectory enabled, do not show…
Browse files Browse the repository at this point in the history
… page if updated

Close #1715
  • Loading branch information
develar committed Jan 30, 2018
1 parent f545d1e commit 5b71f6d
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/builder-util/src/asyncTaskManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class AsyncTaskManager {

this.tasks.push(promise
.catch(it => {
log.debug({error: it.message}, "async task error")
log.debug({error: it.message || it.toString()}, "async task error")
this.errors.push(it)
return BluebirdPromise.resolve(null)
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class NsisTarget extends Target {
const sharedHeader = await this.computeCommonInstallerScriptHeader()
const script = isPortable ? await readFile(path.join(nsisTemplatesDir, "portable.nsi"), "utf8") : await this.computeScriptAndSignUninstaller(defines, commands, installerPath, sharedHeader)
await this.executeMakensis(defines, commands, sharedHeader + await this.computeFinalScript(script, true))
await BluebirdPromise.all<any>([packager.sign(installerPath), defines.UNINSTALLER_OUT_FILE == null ? BluebirdPromise.resolve() : unlink(defines.UNINSTALLER_OUT_FILE)])
await Promise.all<any>([packager.sign(installerPath), defines.UNINSTALLER_OUT_FILE == null ? Promise.resolve() : unlink(defines.UNINSTALLER_OUT_FILE)])

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
!endif

!ifmacrodef licensePage
!insertmacro licensePageHelper
!insertmacro skipPageIfUpdated
!insertmacro licensePage
!endif

Expand All @@ -32,6 +32,7 @@
!ifdef allowToChangeInstallationDirectory
!include StrContains.nsh

!insertmacro skipPageIfUpdated
!insertmacro MUI_PAGE_DIRECTORY

# pageDirectory leave doesn't work (it seems because $INSTDIR is set after custom leave function)
Expand Down
24 changes: 20 additions & 4 deletions packages/electron-builder-lib/templates/nsis/common.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,17 @@ Name "${PRODUCT_NAME}"
!endif
!macroend

!macro licensePageHelper
Function licensePre
!macro skipPageIfUpdated
!define UniqueID ${__LINE__}

Function skipPageIfUpdated_${UniqueID}
${if} ${isUpdated}
Abort
${endif}
FunctionEnd

!define MUI_PAGE_CUSTOMFUNCTION_PRE licensePre
!define MUI_PAGE_CUSTOMFUNCTION_PRE skipPageIfUpdated_${UniqueID}
!undef UniqueID
!macroend

!macro StartApp
Expand All @@ -82,4 +85,17 @@ Name "${PRODUCT_NAME}"
${endif}

${StdUtils.ExecShellAsUser} $0 "$launchLink" "open" "$startAppArgs"
!macroend
!macroend

!ifndef BUILD_UNINSTALLER
Var isTryToKeepShortcuts

!macro setIsTryToKeepShortcuts
StrCpy $isTryToKeepShortcuts "true"
!ifdef allowToChangeInstallationDirectory
${ifNot} ${isUpdated}
StrCpy $isTryToKeepShortcuts "false"
${endIf}
!endif
!macroend
!endif
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@
StrCpy $0 "/allusers"
${endif}

!ifndef allowToChangeInstallationDirectory
!insertMacro setIsTryToKeepShortcuts

${if} $isTryToKeepShortcuts == "true"
ReadRegStr $R5 SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" KeepShortcuts
# if true, it means that old uninstaller supports --keep-shortcuts flag
${if} $R5 == "true"
${andIf} ${FileExists} "$appExe"
StrCpy $0 "$0 --keep-shortcuts"
${endIf}
!endif
${endIf}

${if} ${isDeleteAppData}
StrCpy $0 "$0 --delete-app-data"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ StrCpy $appExe "$INSTDIR\${APP_EXECUTABLE_FILENAME}"

Var /GLOBAL keepShortcuts
StrCpy $keepShortcuts "false"
!ifndef allowToChangeInstallationDirectory
!insertMacro setIsTryToKeepShortcuts
${if} $isTryToKeepShortcuts == "true"
ReadRegStr $R1 SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" KeepShortcuts

${if} $R1 == "true"
${andIf} ${FileExists} "$appExe"
StrCpy $keepShortcuts "true"
${endIf}
!endif
${endif}

!insertmacro uninstallOldVersion SHELL_CONTEXT
${if} $installMode == "all"
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder-lib/templates/nsis/oneClick.nsh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
!ifndef BUILD_UNINSTALLER
!ifmacrodef licensePage
!insertmacro licensePageHelper
!insertmacro skipPageIfUpdated
!insertmacro licensePage
!endif
!endif
Expand Down
2 changes: 1 addition & 1 deletion test/out/mac/__snapshots__/dmgTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Object {
exports[`bundleShortVersion 2`] = `
Object {
"AsarIntegrity": "{\\"checksums\\":{\\"app.asar\\":\\"hash\\",\\"electron.asar\\":\\"hash\\"}}",
"BuildMachineOSBuild": "16G29",
"BuildMachineOSBuild": "16G1114",
"CFBundleDisplayName": "BundleShortVersion",
"CFBundleExecutable": "BundleShortVersion",
"CFBundleIconFile": "BundleShortVersion.icns",
Expand Down
3 changes: 3 additions & 0 deletions test/out/mac/__snapshots__/macArchiveTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Array [
"Test App ßW.app/Contents/Frameworks/ReactiveCocoa.framework/ReactiveCocoa",
"Test App ßW.app/Contents/Frameworks/ReactiveCocoa.framework/Resources",
"Test App ßW.app/Contents/Frameworks/ReactiveCocoa.framework/Versions",
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/.DS_Store",
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Headers",
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Modules",
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Resources",
Expand All @@ -151,6 +152,7 @@ Array [
"Test App ßW.app/Contents/Frameworks/Mantle.framework/Versions/Current",
"Test App ßW.app/Contents/Frameworks/ReactiveCocoa.framework/Versions/A",
"Test App ßW.app/Contents/Frameworks/ReactiveCocoa.framework/Versions/Current",
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Versions/.DS_Store",
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Versions/A",
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Versions/Current",
"Test App ßW.app/Contents/Frameworks/Test App ßW Helper EH.app/Contents/Info.plist",
Expand All @@ -173,6 +175,7 @@ Array [
"Test App ßW.app/Contents/Frameworks/ReactiveCocoa.framework/Versions/A/Modules",
"Test App ßW.app/Contents/Frameworks/ReactiveCocoa.framework/Versions/A/ReactiveCocoa",
"Test App ßW.app/Contents/Frameworks/ReactiveCocoa.framework/Versions/A/Resources",
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Versions/A/.DS_Store",
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Versions/A/Headers",
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Versions/A/Modules",
"Test App ßW.app/Contents/Frameworks/Squirrel.framework/Versions/A/Resources",
Expand Down
2 changes: 1 addition & 1 deletion test/src/mac/dmgTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ test.ifAll.ifMac("retina background as 2 png", () => {
})
})

test.ifMac("no Applications link", () => {
test.ifMac.ifAll("no Applications link", () => {
return assertPack("test-app-one", {
targets: Platform.MAC.createTarget(),
config: {
Expand Down
5 changes: 2 additions & 3 deletions test/src/windows/assistedInstallerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ test.ifNotCiMac("assisted", app({
}
}, {
signedWin: true,
projectDirCreated: projectDir => {
return copyTestAsset("license.txt", path.join(projectDir, "build", "license.txt"))
},
projectDirCreated: projectDir => copyTestAsset("license.txt", path.join(projectDir, "build", "license.txt")),
}))

test.ifAll.ifNotCiMac("allowElevation false, app requestedExecutionLevel admin", app({
Expand Down Expand Up @@ -132,6 +130,7 @@ test.ifAll.ifNotCiMac("allowToChangeInstallationDirectory", app({
}, {
projectDirCreated: async projectDir => {
await writeFile(path.join(projectDir, "build", "release-notes.md"), "New release with new bugs and\n\nwithout features")
await copyTestAsset("license.txt", path.join(projectDir, "build", "license.txt"))
},
packed: async context => {
await expectUpdateMetadata(context, archFromString(process.arch))
Expand Down

0 comments on commit 5b71f6d

Please sign in to comment.