Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep existing desktop/menu/taskbar shortcuts after update #1653

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions packages/electron-builder/templates/nsis/installSection.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
StrCpy $0 "$0 --delete-app-data"
${else}
# always pass --updated flag - to ensure that if DELETE_APP_DATA_ON_UNINSTALL is defined, user data will be not removed
StrCpy $0 "$0 --updated"
StrCpy $0 "$0 --updated $shortcuts"
${endif}

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

StrCpy $appExe "$INSTDIR\${APP_EXECUTABLE_FILENAME}"
Var /GLOBAL shortcuts
StrCpy $shortcuts "--recreate-shortcuts"
!ifndef allowToChangeInstallationDirectory
${If} ${FileExists} `$appExe`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why double quotes not used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad cleanup!! No evaluation is expected here. I'll update, thanks!

StrCpy $shortcuts "--keep-shortcuts"
${EndIf}
!endif

!ifdef ONE_CLICK
!ifdef HEADER_ICO
File /oname=$PLUGINSDIR\installerHeaderico.ico "${HEADER_ICO}"
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 == "--recreate-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
23 changes: 16 additions & 7 deletions packages/electron-builder/templates/nsis/uninstaller.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,22 @@ 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
DetailPrint $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 All @@ -49,7 +59,6 @@ Section "un.install"
StrCpy $isDeleteAppData "0"

ClearErrors
${GetParameters} $R0
${GetOptions} $R0 "--delete-app-data" $R1
${if} ${Errors}
!ifdef DELETE_APP_DATA_ON_UNINSTALL
Expand Down Expand Up @@ -85,4 +94,4 @@ Section "un.install"
!ifdef ONE_CLICK
!insertmacro quitSuccess
!endif
SectionEnd
SectionEnd