Skip to content

Commit 38df6ea

Browse files
authored
fix(nsis): fix regression in shortcuts pointing to a non-existing file (#9909)
1 parent a0a76ce commit 38df6ea

File tree

2 files changed

+83
-44
lines changed

2 files changed

+83
-44
lines changed

Diff for: .changes/nsis-shortcuts-regression.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-bundler": "patch:bug"
3+
---
4+
5+
Fix regression in NSIS where it created shortcuts that point to non-existent files.
6+

Diff for: tooling/bundler/src/bundle/windows/templates/installer.nsi

+77-44
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ ${StrLoc}
5151
!define UNINSTALLERSIGNCOMMAND "{{uninstaller_sign_cmd}}"
5252
!define ESTIMATEDSIZE "{{estimated_size}}"
5353

54+
Var PassiveMode
55+
Var UpdateMode
56+
Var NoShortcutMode
57+
5458
Name "${PRODUCTNAME}"
5559
BrandingText "${COPYRIGHT}"
5660
OutFile "${OUTFILE}"
@@ -194,21 +198,21 @@ Function PageReinstall
194198
nsis_tauri_utils::SemverCompare "${VERSION}" $R0
195199
Pop $R0
196200
; Reinstalling the same version
197-
${If} $R0 == 0
201+
${If} $R0 = 0
198202
StrCpy $R1 "$(alreadyInstalledLong)"
199203
StrCpy $R2 "$(addOrReinstall)"
200204
StrCpy $R3 "$(uninstallApp)"
201205
!insertmacro MUI_HEADER_TEXT "$(alreadyInstalled)" "$(chooseMaintenanceOption)"
202206
StrCpy $R5 "2"
203207
; Upgrading
204-
${ElseIf} $R0 == 1
208+
${ElseIf} $R0 = 1
205209
StrCpy $R1 "$(olderOrUnknownVersionInstalled)"
206210
StrCpy $R2 "$(uninstallBeforeInstalling)"
207211
StrCpy $R3 "$(dontUninstall)"
208212
!insertmacro MUI_HEADER_TEXT "$(alreadyInstalled)" "$(choowHowToInstall)"
209213
StrCpy $R5 "1"
210214
; Downgrading
211-
${ElseIf} $R0 == -1
215+
${ElseIf} $R0 = -1
212216
StrCpy $R1 "$(newerVersionInstalled)"
213217
StrCpy $R2 "$(uninstallBeforeInstalling)"
214218
!if "${ALLOWDOWNGRADES}" == "true"
@@ -232,7 +236,7 @@ Function PageReinstall
232236

233237
nsDialogs::Create 1018
234238
Pop $R4
235-
${IfThen} $(^RTL) == 1 ${|} nsDialogs::SetRTL $(^RTL) ${|}
239+
${IfThen} $(^RTL) = 1 ${|} nsDialogs::SetRTL $(^RTL) ${|}
236240

237241
${NSD_CreateLabel} 0 0 100% 24u $R1
238242
Pop $R1
@@ -245,14 +249,14 @@ Function PageReinstall
245249
Pop $R3
246250
; Disable this radio button if downgrading and downgrades are disabled
247251
!if "${ALLOWDOWNGRADES}" == "false"
248-
${IfThen} $R0 == -1 ${|} EnableWindow $R3 0 ${|}
252+
${IfThen} $R0 = -1 ${|} EnableWindow $R3 0 ${|}
249253
!endif
250254
${NSD_OnClick} $R3 PageReinstallUpdateSelection
251255

252256
; Check the first radio button if this the first time
253257
; we enter this page or if the second button wasn't
254258
; selected the last time we were on this page
255-
${If} $ReinstallPageCheck != 2
259+
${If} $ReinstallPageCheck <> 2
256260
SendMessage $R2 ${BM_SETCHECK} ${BST_CHECKED} 0
257261
${Else}
258262
SendMessage $R3 ${BM_SETCHECK} ${BST_CHECKED} 0
@@ -291,7 +295,11 @@ Function PageLeaveReinstall
291295
${Else}
292296
ReadRegStr $4 SHCTX "${MANUPRODUCTKEY}" ""
293297
ReadRegStr $R1 SHCTX "${UNINSTKEY}" "UninstallString"
294-
ExecWait '$R1 /P _?=$4' $0
298+
${If} $UpdateMode = 1
299+
ExecWait '$R1 /UPDATE /P _?=$4' $0
300+
${Else}
301+
ExecWait '$R1 /P _?=$4' $0
302+
${EndIf}
295303
${EndIf}
296304

297305
BringToFront
@@ -339,7 +347,7 @@ Var AppStartMenuFolder
339347
!define MUI_FINISHPAGE_SHOWREADME_FUNCTION CreateDesktopShortcut
340348
; Show run app after installation.
341349
!define MUI_FINISHPAGE_RUN "$INSTDIR\${MAINBINARYNAME}.exe"
342-
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive
350+
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassiveButUpdateShortcutIfUpdate
343351
!insertmacro MUI_PAGE_FINISH
344352

345353
; Uninstaller Pages
@@ -350,7 +358,7 @@ Var DeleteAppDataCheckboxState
350358
!define MUI_PAGE_CUSTOMFUNCTION_SHOW un.ConfirmShow
351359
Function un.ConfirmShow ; Add add a `Delete app data` check box
352360
FindWindow $1 "#32770" "" $HWNDPARENT ; Find inner dialog
353-
${If} $(^RTL) == 1
361+
${If} $(^RTL) = 1
354362
System::Call 'USER32::CreateWindowEx(i${__NSD_CheckBox_EXSTYLE}|${WS_EX_LAYOUTRTL},t"${__NSD_CheckBox_CLASS}",t "$(deleteAppData)",i${__NSD_CheckBox_STYLE},i 50,i 100,i 400, i 25,i$1,i0,i0,i0)i.s'
355363
${Else}
356364
System::Call 'USER32::CreateWindowEx(i${__NSD_CheckBox_EXSTYLE},t"${__NSD_CheckBox_CLASS}",t "$(deleteAppData)",i${__NSD_CheckBox_STYLE},i 0,i 100,i 400, i 25,i$1,i0,i0,i0)i.s'
@@ -377,13 +385,15 @@ FunctionEnd
377385
!include "{{this}}"
378386
{{/each}}
379387

380-
Var PassiveMode
381-
Var UpdateMode
382388
Function .onInit
383389
${GetOptions} $CMDLINE "/P" $PassiveMode
384390
IfErrors +2 0
385391
StrCpy $PassiveMode 1
386392

393+
${GetOptions} $CMDLINE "/NS" $NoShortcutMode
394+
IfErrors +2 0
395+
StrCpy $NoShortcutMode 1
396+
387397
${GetOptions} $CMDLINE "/UPDATE" $UpdateMode
388398
IfErrors +2 0
389399
StrCpy $UpdateMode 1
@@ -427,9 +437,9 @@ Section EarlyChecks
427437
!if "${ALLOWDOWNGRADES}" == "false"
428438
IfSilent 0 silent_downgrades_done
429439
; If downgrading
430-
${If} $R0 == -1
440+
${If} $R0 = -1
431441
System::Call 'kernel32::AttachConsole(i -1)i.r0'
432-
${If} $0 != 0
442+
${If} $0 <> 0
433443
System::Call 'kernel32::GetStdHandle(i -11)i.r0'
434444
System::call 'kernel32::SetConsoleTextAttribute(i r0, i 0x0004)' ; set red color
435445
FileWrite $0 "$(silentDowngrades)"
@@ -462,7 +472,7 @@ Section WebView2
462472
DetailPrint "$(webview2Downloading)"
463473
NSISdl::download "https://go.microsoft.com/fwlink/p/?LinkId=2124703" "$TEMP\MicrosoftEdgeWebview2Setup.exe"
464474
Pop $0
465-
${If} $0 == 0
475+
${If} $0 = 0
466476
DetailPrint "$(webview2DownloadSuccess)"
467477
${Else}
468478
DetailPrint "$(webview2DownloadError)"
@@ -494,7 +504,7 @@ Section WebView2
494504
DetailPrint "$(installingWebview2)"
495505
; $6 holds the path to the webview2 installer
496506
ExecWait "$6 ${WEBVIEW2INSTALLERARGS} /install" $1
497-
${If} $1 == 0
507+
${If} $1 = 0
498508
DetailPrint "$(webview2InstallSuccess)"
499509
${Else}
500510
DetailPrint "$(webview2InstallError)"
@@ -567,40 +577,32 @@ Section Install
567577
WriteRegDWORD SHCTX "${UNINSTKEY}" "NoRepair" "1"
568578
WriteRegDWORD SHCTX "${UNINSTKEY}" "EstimatedSize" "${ESTIMATEDSIZE}"
569579

570-
; Create start menu shortcut (GUI)
580+
; Create start menu shortcut
571581
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
572582
Call CreateStartMenuShortcut
573583
!insertmacro MUI_STARTMENU_WRITE_END
574584

575-
; Create shortcuts for silent and passive installers, which
576-
; can be disabled by passing `/NS` or `/UPDATE` flag.
577-
;
578-
; GUI installer has buttons for users to control creating them.
579-
IfSilent check_ns_flag 0
580-
${IfThen} $PassiveMode == 1 ${|} Goto check_ns_flag ${|}
581-
Goto shortcuts_done
582-
check_ns_flag:
583-
${GetOptions} $CMDLINE "/NS" $R0
584-
IfErrors 0 shortcuts_done
585-
${If} $UpdateMode <> 1
586-
Call CreateDesktopShortcut
587-
Call CreateStartMenuShortcut
588-
${EndIf}
589-
shortcuts_done:
585+
; Create desktop shortcut for silent and passive installers
586+
; because finish page will be skipped
587+
IfSilent create_shortcut 0
588+
StrCmp $PassiveMode "1" create_shortcut shortcut_done
589+
create_shortcut:
590+
Call CreateDesktopShortcut
591+
shortcut_done:
590592

591593
!ifdef NSIS_HOOK_POSTINSTALL
592594
!insertmacro "${NSIS_HOOK_POSTINSTALL}"
593595
!endif
594596

595597
; Auto close this page for passive mode
596-
${IfThen} $PassiveMode == 1 ${|} SetAutoClose true ${|}
598+
${IfThen} $PassiveMode = 1 ${|} SetAutoClose true ${|}
597599
SectionEnd
598600

599601
Function .onInstSuccess
600602
; Check for `/R` flag only in silent and passive installers because
601603
; GUI installer has a toggle for the user to (re)start the app
602604
IfSilent check_r_flag 0
603-
${IfThen} $PassiveMode == 1 ${|} Goto check_r_flag ${|}
605+
${IfThen} $PassiveMode = 1 ${|} Goto check_r_flag ${|}
604606
Goto run_done
605607
check_r_flag:
606608
${GetOptions} $CMDLINE "/R" $R0
@@ -618,12 +620,13 @@ Function un.onInit
618620
!endif
619621

620622
!insertmacro MUI_UNGETLANGUAGE
621-
FunctionEnd
622623

623-
Section Uninstall
624624
${GetOptions} $CMDLINE "/UPDATE" $UpdateMode
625625
IfErrors +2 0
626626
StrCpy $UpdateMode 1
627+
FunctionEnd
628+
629+
Section Uninstall
627630

628631
!insertmacro CheckIfAppIsRunning
629632

@@ -675,13 +678,13 @@ Section Uninstall
675678

676679
; Remove start menu shortcut
677680
!insertmacro MUI_STARTMENU_GETFOLDER Application $AppStartMenuFolder
678-
!insertmacro UnpinShortcut "$SMPROGRAMS\$AppStartMenuFolder\${MAINBINARYNAME}.lnk"
679-
Delete "$SMPROGRAMS\$AppStartMenuFolder\${MAINBINARYNAME}.lnk"
681+
!insertmacro UnpinShortcut "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk"
682+
Delete "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk"
680683
RMDir "$SMPROGRAMS\$AppStartMenuFolder"
681684

682685
; Remove desktop shortcuts
683-
!insertmacro UnpinShortcut "$DESKTOP\${MAINBINARYNAME}.lnk"
684-
Delete "$DESKTOP\${MAINBINARYNAME}.lnk"
686+
!insertmacro UnpinShortcut "$DESKTOP\${PRODUCTNAME}.lnk"
687+
Delete "$DESKTOP\${PRODUCTNAME}.lnk"
685688
${EndIf}
686689

687690
; Remove registry information for add/remove programs
@@ -721,16 +724,46 @@ Function RestorePreviousInstallLocation
721724
FunctionEnd
722725

723726
Function SkipIfPassive
724-
${IfThen} $PassiveMode == 1 ${|} Abort ${|}
727+
${IfThen} $PassiveMode = 1 ${|} Abort ${|}
728+
FunctionEnd
729+
730+
Function SkipIfPassiveButUpdateShortcutIfUpdate
731+
${If} $PassiveMode = 1
732+
Call CreateDesktopShortcut
733+
Abort
734+
${EndIf}
725735
FunctionEnd
726736

727737
Function CreateDesktopShortcut
728-
CreateShortcut "$DESKTOP\${MAINBINARYNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe"
729-
!insertmacro SetLnkAppUserModelId "$DESKTOP\${MAINBINARYNAME}.lnk"
738+
; Skip creating shortcut if in update mode
739+
; and shortcuts doesn't exist, which means user deleted it
740+
; so we respect that.
741+
${If} $UpdateMode = 1
742+
IfFileExists "$DESKTOP\${PRODUCTNAME}.lnk" +2 0
743+
Return
744+
${EndIf}
745+
746+
${If} $NoShortcutMode = 1
747+
Return
748+
${EndIf}
749+
750+
CreateShortcut "$DESKTOP\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe"
751+
!insertmacro SetLnkAppUserModelId "$DESKTOP\${PRODUCTNAME}.lnk"
730752
FunctionEnd
731753

732754
Function CreateStartMenuShortcut
755+
; Skip creating shortcut if in update mode.
756+
; See `CreateDesktopShortcut` above.
757+
${If} $UpdateMode = 1
758+
IfFileExists "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" +2 0
759+
Return
760+
${EndIf}
761+
762+
${If} $NoShortcutMode = 1
763+
Return
764+
${EndIf}
765+
733766
CreateDirectory "$SMPROGRAMS\$AppStartMenuFolder"
734-
CreateShortcut "$SMPROGRAMS\$AppStartMenuFolder\${MAINBINARYNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe"
735-
!insertmacro SetLnkAppUserModelId "$SMPROGRAMS\$AppStartMenuFolder\${MAINBINARYNAME}.lnk"
767+
CreateShortcut "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe"
768+
!insertmacro SetLnkAppUserModelId "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk"
736769
FunctionEnd

0 commit comments

Comments
 (0)