From 683d58c442f1677dd4d286d1a4ebed3d594c895d Mon Sep 17 00:00:00 2001 From: develar Date: Tue, 28 Mar 2017 10:10:25 +0200 Subject: [PATCH] fix(nsis): StartApp doesn't work if menuCategory used Close #1151, Close #1412 --- packages/electron-builder/src/targets/nsis.ts | 2 +- .../templates/nsis/boringInstaller.nsh | 4 ++-- .../templates/nsis/installSection.nsh | 2 +- .../templates/nsis/installer.nsi | 6 +++--- .../templates/nsis/oneClick.nsh | 19 +++++++++++-------- test/src/windows/oneClickInstallerTest.ts | 2 +- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/packages/electron-builder/src/targets/nsis.ts b/packages/electron-builder/src/targets/nsis.ts index 10b95bd996b..3e846cdf446 100644 --- a/packages/electron-builder/src/targets/nsis.ts +++ b/packages/electron-builder/src/targets/nsis.ts @@ -282,7 +282,7 @@ export default class NsisTarget extends Target { defines.allowToChangeInstallationDirectory = null } - if (options.menuCategory != null) { + if (options.menuCategory != null && options.menuCategory !== false) { const menu = sanitizeFileName(options.menuCategory === true ? packager.appInfo.companyName : options.menuCategory) if (!isEmptyOrSpaces(menu)) { defines.MENU_FILENAME = menu diff --git a/packages/electron-builder/templates/nsis/boringInstaller.nsh b/packages/electron-builder/templates/nsis/boringInstaller.nsh index 7990dfd563f..28b8f90fbc9 100644 --- a/packages/electron-builder/templates/nsis/boringInstaller.nsh +++ b/packages/electron-builder/templates/nsis/boringInstaller.nsh @@ -8,9 +8,9 @@ !ifndef BUILD_UNINSTALLER Function StartApp ${if} ${Updated} - ${StdUtils.ExecShellAsUser} $0 "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" "open" "--updated" + ${StdUtils.ExecShellAsUser} $0 "$startMenuLink" "open" "--updated" ${else} - ${StdUtils.ExecShellAsUser} $0 "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" "open" "" + ${StdUtils.ExecShellAsUser} $0 "$startMenuLink" "open" "" ${endif} FunctionEnd diff --git a/packages/electron-builder/templates/nsis/installSection.nsh b/packages/electron-builder/templates/nsis/installSection.nsh index 80420de75b0..b692aef5dfb 100644 --- a/packages/electron-builder/templates/nsis/installSection.nsh +++ b/packages/electron-builder/templates/nsis/installSection.nsh @@ -184,7 +184,7 @@ WinShell::SetLnkAUMI "$desktopLink" "${APP_ID}" ${IfNot} ${Silent} # otherwise app window will be in backround HideWindow - Call StartApp + !insertmacro StartApp ${EndIf} !endif !insertmacro quitSuccess diff --git a/packages/electron-builder/templates/nsis/installer.nsi b/packages/electron-builder/templates/nsis/installer.nsi index 578e62a7acb..df0d268e444 100644 --- a/packages/electron-builder/templates/nsis/installer.nsi +++ b/packages/electron-builder/templates/nsis/installer.nsi @@ -1,3 +1,6 @@ +Var startMenuLink +Var desktopLink + !include "common.nsh" !include "MUI2.nsh" !include "multiUser.nsh" @@ -23,9 +26,6 @@ !insertmacro customHeader !endif -Var startMenuLink -Var desktopLink - !ifdef BUILD_UNINSTALLER SilentInstall silent !else diff --git a/packages/electron-builder/templates/nsis/oneClick.nsh b/packages/electron-builder/templates/nsis/oneClick.nsh index 3b9ac68d087..b8ed735397d 100644 --- a/packages/electron-builder/templates/nsis/oneClick.nsh +++ b/packages/electron-builder/templates/nsis/oneClick.nsh @@ -1,17 +1,20 @@ !ifndef BUILD_UNINSTALLER !ifdef RUN_AFTER_FINISH !include StdUtils.nsh - Function StartApp + !macro StartApp + Var /GLOBAL startAppArgs + ${if} ${Updated} + StrCpy $startAppArgs "--updated" + ${else} + StrCpy $startAppArgs "" + ${endif} + !ifdef INSTALL_MODE_PER_ALL_USERS - ${StdUtils.ExecShellAsUser} $0 "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" "open" "" + ${StdUtils.ExecShellAsUser} $0 $startMenuLink "open" "$startAppArgs" !else - ${if} ${Updated} - ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" "--updated" - ${else} - ExecShell "" "$SMPROGRAMS\${PRODUCT_FILENAME}.lnk" - ${endif} + ExecShell "" "$startMenuLink" "$startAppArgs" !endif - FunctionEnd + !macroend !endif !ifmacrodef licensePage diff --git a/test/src/windows/oneClickInstallerTest.ts b/test/src/windows/oneClickInstallerTest.ts index dfb1f07497f..26455c0a96d 100644 --- a/test/src/windows/oneClickInstallerTest.ts +++ b/test/src/windows/oneClickInstallerTest.ts @@ -119,7 +119,7 @@ test.ifAll("menuCategory", app({ }, config: { nsis: { - perMachine: true, + oneClick: false, menuCategory: true, artifactName: "${productName} CustomName ${version}.${ext}" },