Skip to content

Commit 2f3d7d8

Browse files
MariaDimadevelar
authored andcommitted
fix(nsis): Keep existing desktop/menu/taskbar shortcuts after update
Close #1653
1 parent 5e0a646 commit 2f3d7d8

File tree

2 files changed

+39
-21
lines changed

2 files changed

+39
-21
lines changed

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

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
StrCpy $0 "$0 --updated"
4040
${endif}
4141

42-
ExecWait '"$PLUGINSDIR\old-uninstaller.exe" /S /KEEP_APP_DATA $0 _?=$R1'
42+
ExecWait '"$PLUGINSDIR\old-uninstaller.exe" /S /KEEP_APP_DATA $0 $shortcuts _?=$R1'
4343
${endif}
4444
${endif}
4545
!macroend
@@ -84,6 +84,15 @@ ${IfNot} ${Silent}
8484
SetDetailsPrint none
8585
${endif}
8686

87+
StrCpy $appExe "$INSTDIR\${APP_EXECUTABLE_FILENAME}"
88+
Var /GLOBAL shortcuts
89+
StrCpy $shortcuts ""
90+
!ifndef allowToChangeInstallationDirectory
91+
${if} ${FileExists} "$appExe"
92+
StrCpy $shortcuts "--keep-shortcuts"
93+
${endIf}
94+
!endif
95+
8796
!ifdef ONE_CLICK
8897
!ifdef HEADER_ICO
8998
File /oname=$PLUGINSDIR\installerHeaderico.ico "${HEADER_ICO}"
@@ -102,7 +111,7 @@ ${endif}
102111
${endif}
103112
!insertmacro CHECK_APP_RUNNING
104113
!else
105-
${IfNot} ${UAC_IsInnerInstance}
114+
${ifNot} ${UAC_IsInnerInstance}
106115
!insertmacro CHECK_APP_RUNNING
107116
${endif}
108117
!endif
@@ -168,27 +177,27 @@ SetOutPath $INSTDIR
168177

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

171-
StrCpy $appExe "$INSTDIR\${APP_EXECUTABLE_FILENAME}"
172180
!insertmacro registryAddInstallInfo
173-
174181
!insertmacro setLinkVars
175182

176183
!ifdef MENU_FILENAME
177184
CreateDirectory "$SMPROGRAMS\${MENU_FILENAME}"
178185
!endif
179186

180-
# create shortcuts in the start menu and on the desktop
181-
# shortcut for uninstall is bad cause user can choose this by mistake during search, so, we don't add it
182-
CreateShortCut "$startMenuLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
183-
184-
${GetParameters} $R0
185-
${GetOptions} $R0 "--no-desktop-shortcut" $R1
186-
${If} ${Errors}
187-
CreateShortCut "$desktopLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
188-
${EndIf}
189-
190-
WinShell::SetLnkAUMI "$startMenuLink" "${APP_ID}"
191-
WinShell::SetLnkAUMI "$desktopLink" "${APP_ID}"
187+
${if} $shortcuts == ""
188+
# create shortcuts in the start menu and on the desktop
189+
# shortcut for uninstall is bad cause user can choose this by mistake during search, so, we don't add it
190+
CreateShortCut "$startMenuLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
191+
WinShell::SetLnkAUMI "$startMenuLink" "${APP_ID}"
192+
193+
ClearErrors
194+
${GetParameters} $R0
195+
${GetOptions} $R0 "--no-desktop-shortcut" $R1
196+
${If} ${Errors}
197+
CreateShortCut "$desktopLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
198+
WinShell::SetLnkAUMI "$desktopLink" "${APP_ID}"
199+
${endIf}
200+
${endif}
192201

193202
!ifmacrodef registerFileAssociations
194203
!insertmacro registerFileAssociations

packages/electron-builder/templates/nsis/uninstaller.nsh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,21 @@ Section "un.install"
2727

2828
!insertmacro setLinkVars
2929

30-
WinShell::UninstAppUserModelId "${APP_ID}"
31-
WinShell::UninstShortcut "$startMenuLink"
32-
WinShell::UninstShortcut "$desktopLink"
30+
ClearErrors
31+
${GetParameters} $R0
32+
DetailPrint $R0
33+
${GetOptions} $R0 "--keep-shortcuts" $R1
34+
${if} ${Errors}
35+
WinShell::UninstAppUserModelId "${APP_ID}"
36+
WinShell::UninstShortcut "$startMenuLink"
37+
WinShell::UninstShortcut "$desktopLink"
3338

34-
Delete "$startMenuLink"
35-
Delete "$desktopLink"
39+
Delete "$startMenuLink"
40+
Delete "$desktopLink"
41+
42+
# Refresh the desktop
43+
System::Call 'shell32::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)'
44+
${endif}
3645

3746
!ifmacrodef unregisterFileAssociations
3847
!insertmacro unregisterFileAssociations

0 commit comments

Comments
 (0)