Skip to content

Commit

Permalink
fix(nsis): Keep existing desktop/menu/taskbar shortcuts after update
Browse files Browse the repository at this point in the history
Close #1653
  • Loading branch information
MariaDima authored and develar committed Jun 13, 2017
1 parent 5e0a646 commit 2f3d7d8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
41 changes: 25 additions & 16 deletions packages/electron-builder/templates/nsis/installSection.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
StrCpy $0 "$0 --updated"
${endif}

ExecWait '"$PLUGINSDIR\old-uninstaller.exe" /S /KEEP_APP_DATA $0 _?=$R1'
ExecWait '"$PLUGINSDIR\old-uninstaller.exe" /S /KEEP_APP_DATA $0 $shortcuts _?=$R1'
${endif}
${endif}
!macroend
Expand Down Expand Up @@ -84,6 +84,15 @@ ${IfNot} ${Silent}
SetDetailsPrint none
${endif}

StrCpy $appExe "$INSTDIR\${APP_EXECUTABLE_FILENAME}"
Var /GLOBAL shortcuts
StrCpy $shortcuts ""
!ifndef allowToChangeInstallationDirectory
${if} ${FileExists} "$appExe"
StrCpy $shortcuts "--keep-shortcuts"
${endIf}
!endif

!ifdef ONE_CLICK
!ifdef HEADER_ICO
File /oname=$PLUGINSDIR\installerHeaderico.ico "${HEADER_ICO}"
Expand All @@ -102,7 +111,7 @@ ${endif}
${endif}
!insertmacro CHECK_APP_RUNNING
!else
${IfNot} ${UAC_IsInnerInstance}
${ifNot} ${UAC_IsInnerInstance}
!insertmacro CHECK_APP_RUNNING
${endif}
!endif
Expand Down Expand Up @@ -168,27 +177,27 @@ SetOutPath $INSTDIR

File "/oname=${UNINSTALL_FILENAME}" "${UNINSTALLER_OUT_FILE}"

StrCpy $appExe "$INSTDIR\${APP_EXECUTABLE_FILENAME}"
!insertmacro registryAddInstallInfo

!insertmacro setLinkVars

!ifdef MENU_FILENAME
CreateDirectory "$SMPROGRAMS\${MENU_FILENAME}"
!endif

# create shortcuts in the start menu and on the desktop
# shortcut for uninstall is bad cause user can choose this by mistake during search, so, we don't add it
CreateShortCut "$startMenuLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"

${GetParameters} $R0
${GetOptions} $R0 "--no-desktop-shortcut" $R1
${If} ${Errors}
CreateShortCut "$desktopLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
${EndIf}

WinShell::SetLnkAUMI "$startMenuLink" "${APP_ID}"
WinShell::SetLnkAUMI "$desktopLink" "${APP_ID}"
${if} $shortcuts == ""
# create shortcuts in the start menu and on the desktop
# shortcut for uninstall is bad cause user can choose this by mistake during search, so, we don't add it
CreateShortCut "$startMenuLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
WinShell::SetLnkAUMI "$startMenuLink" "${APP_ID}"

ClearErrors
${GetParameters} $R0
${GetOptions} $R0 "--no-desktop-shortcut" $R1
${If} ${Errors}
CreateShortCut "$desktopLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
WinShell::SetLnkAUMI "$desktopLink" "${APP_ID}"
${endIf}
${endif}

!ifmacrodef registerFileAssociations
!insertmacro registerFileAssociations
Expand Down
19 changes: 14 additions & 5 deletions packages/electron-builder/templates/nsis/uninstaller.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@ Section "un.install"

!insertmacro setLinkVars

WinShell::UninstAppUserModelId "${APP_ID}"
WinShell::UninstShortcut "$startMenuLink"
WinShell::UninstShortcut "$desktopLink"
ClearErrors
${GetParameters} $R0
DetailPrint $R0
${GetOptions} $R0 "--keep-shortcuts" $R1
${if} ${Errors}
WinShell::UninstAppUserModelId "${APP_ID}"
WinShell::UninstShortcut "$startMenuLink"
WinShell::UninstShortcut "$desktopLink"

Delete "$startMenuLink"
Delete "$desktopLink"
Delete "$startMenuLink"
Delete "$desktopLink"

# Refresh the desktop
System::Call 'shell32::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)'
${endif}

!ifmacrodef unregisterFileAssociations
!insertmacro unregisterFileAssociations
Expand Down

0 comments on commit 2f3d7d8

Please sign in to comment.