juicewrld-desktopsrc-taurinsisinstaller.nsi
1.4.2Released Nov 21, 2026
installer.nsi
1,059 lines35.3 KBNSIS; juicewrld.io's installer: Tauri's NSIS template (tauri-cli 2.12.4, the one `tauri build` uses by itself), with the; changes marked "juicewrld.io:" for a one-click install. On a Tauri upgrade, start from the new version's template; (it is built into the CLI) and make them again:; 1. .onInit: always the /P mode, so a double-click shows no pages to step through: the progress bar only, both; shortcuts, then the app opens (.onInstSuccess).; 2. .onInit: an update (/UPDATE) with nothing installed yet comes from the portable exe: it installs as a first; install does, shortcuts included.; 3. PageLeaveReinstall: whatever version is installed, the same one too, is installed over, never uninstalled first.; 4. Section Install: a copy of the app running from anywhere else (the portable exe) is closed too.; 5. .onInstSuccess: opens the app after a double-click, and after an update when asked to (/R), never with the old; process's arguments (a juicewrld:// sign-in link must not run twice).; The updater runs it as `/S /UPDATE` (plus `/R` from the title bar's Update ready): silent, see plugins.updater in; tauri.conf.json.Unicode trueManifestDPIAware true; Add in `dpiAwareness` `PerMonitorV2` to manifest for Windows 10 1607+ (note this should not affect lower versions since they should be able to ignore this and pick up `dpiAware` `true` set by `ManifestDPIAware true`); Currently undocumented on NSIS's website but is in the Docs folder of source tree, see; https://github.com/kichik/nsis/blob/5fc0b87b819a9eec006df4967d08e522ddd651c9/Docs/src/attributes.but#L286-L300; https://github.com/tauri-apps/tauri/pull/10106ManifestDPIAwareness PerMonitorV2 "{{compression}}" == "none" SetCompress off ; Set the compression algorithm. We default to LZMA. SetCompressor /SOLID "{{compression}}"; Keep above !include to stay ahead of any plugin command; see https://github.com/tauri-apps/tauri/pull/15422#discussion_r3289239624{{#if signed_plugins_path}} "{{signed_plugins_path}}"{{/if}} MUI2.nsh FileFunc.nsh x64.nsh WordFunc.nsh "utils.nsh" "FileAssociation.nsh" "Win\COM.nsh" "Win\Propkey.nsh" "Win\RestartManager.nsh" "StrFunc.nsh"${StrCase}${StrLoc}{{#if installer_hooks}} "{{installer_hooks}}"{{/if}} WEBVIEW2APPGUID "{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" MANUFACTURER "{{manufacturer}}" PRODUCTNAME "{{product_name}}" VERSION "{{version}}" VERSIONWITHBUILD "{{version_with_build}}" HOMEPAGE "{{homepage}}" INSTALLMODE "{{install_mode}}" LICENSE "{{license}}" INSTALLERICON "{{installer_icon}}" SIDEBARIMAGE "{{sidebar_image}}" HEADERIMAGE "{{header_image}}" UNINSTALLERICON "{{uninstaller_icon}}" UNINSTALLERHEADERIMAGE "{{uninstaller_header_image}}" MAINBINARYNAME "{{main_binary_name}}" MAINBINARYSRCPATH "{{main_binary_path}}" BUNDLEID "{{bundle_id}}" COPYRIGHT "{{copyright}}" OUTFILE "{{out_file}}" ARCH "{{arch}}" ADDITIONALPLUGINSPATH "{{additional_plugins_path}}" ALLOWDOWNGRADES "{{allow_downgrades}}" DISPLAYLANGUAGESELECTOR "{{display_language_selector}}" INSTALLWEBVIEW2MODE "{{install_webview2_mode}}" WEBVIEW2INSTALLERARGS "{{webview2_installer_args}}" WEBVIEW2BOOTSTRAPPERPATH "{{webview2_bootstrapper_path}}" WEBVIEW2INSTALLERPATH "{{webview2_installer_path}}" MINIMUMWEBVIEW2VERSION "{{minimum_webview2_version}}" UNINSTKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}" MANUKEY "Software\${MANUFACTURER}" MANUPRODUCTKEY "${MANUKEY}\${PRODUCTNAME}" UNINSTALLERSIGNCOMMAND "{{uninstaller_sign_cmd}}" ESTIMATEDSIZE "{{estimated_size}}" STARTMENUFOLDER "{{start_menu_folder}}"Var PassiveModeVar UpdateModeVar NoShortcutModeVar WixModeVar OldMainBinaryNameName "${PRODUCTNAME}"BrandingText "${COPYRIGHT}"OutFile "${OUTFILE}"; We don't actually use this value as default install path,; it's just for nsis to append the product name folder in the directory selector; https://nsis.sourceforge.io/Reference/InstallDir PLACEHOLDER_INSTALL_DIR "placeholder\${PRODUCTNAME}"InstallDir "${PLACEHOLDER_INSTALL_DIR}"VIProductVersion "${VERSIONWITHBUILD}"VIAddVersionKey "ProductName" "${PRODUCTNAME}"VIAddVersionKey "FileDescription" "${PRODUCTNAME}"VIAddVersionKey "LegalCopyright" "${COPYRIGHT}"VIAddVersionKey "FileVersion" "${VERSION}"VIAddVersionKey "ProductVersion" "${VERSION}"# additional plugins "${ADDITIONALPLUGINSPATH}"; Uninstaller signing command "${UNINSTALLERSIGNCOMMAND}" != "" '${UNINSTALLERSIGNCOMMAND}'; Handle install mode, `perUser`, `perMachine` or `both` "${INSTALLMODE}" == "perMachine" RequestExecutionLevel admin "${INSTALLMODE}" == "currentUser" RequestExecutionLevel user "${INSTALLMODE}" == "both" MULTIUSER_MUI MULTIUSER_INSTALLMODE_INSTDIR "${PRODUCTNAME}" MULTIUSER_INSTALLMODE_COMMANDLINE "${ARCH}" == "x64" MULTIUSER_USE_PROGRAMFILES64 if "${ARCH}" == "arm64" MULTIUSER_USE_PROGRAMFILES64 MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_KEY "${UNINSTKEY}" MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_VALUENAME "CurrentUser" MULTIUSER_INSTALLMODEPAGE_SHOWUSERNAME MULTIUSER_INSTALLMODE_FUNCTION RestorePreviousInstallLocation MULTIUSER_EXECUTIONLEVEL Highest MultiUser.nsh; Installer icon "${INSTALLERICON}" != "" MUI_ICON "${INSTALLERICON}"; Installer sidebar image "${SIDEBARIMAGE}" != "" MUI_WELCOMEFINISHPAGE_BITMAP "${SIDEBARIMAGE}"; Enable header images for installer and uninstaller pages when either image is configured. "${HEADERIMAGE}" != "" MUI_HEADERIMAGE if "${UNINSTALLERHEADERIMAGE}" != "" MUI_HEADERIMAGE; Installer header image "${HEADERIMAGE}" != "" MUI_HEADERIMAGE_BITMAP "${HEADERIMAGE}"; Uninstaller header image "${UNINSTALLERHEADERIMAGE}" != "" MUI_HEADERIMAGE_UNBITMAP "${UNINSTALLERHEADERIMAGE}"; Uninstaller icon "${UNINSTALLERICON}" != "" MUI_UNICON "${UNINSTALLERICON}"; Define registry key to store installer language MUI_LANGDLL_REGISTRY_ROOT "HKCU" MUI_LANGDLL_REGISTRY_KEY "${MANUPRODUCTKEY}" MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"; Installer pages, must be ordered as they appear; 1. Welcome Page MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive MUI_PAGE_WELCOME; 2. License Page (if defined) "${LICENSE}" != "" MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive MUI_PAGE_LICENSE "${LICENSE}"; 3. Install mode (if it is set to `both`) "${INSTALLMODE}" == "both" MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive MULTIUSER_PAGE_INSTALLMODE; 4. Custom page to ask user if he wants to reinstall/uninstall; only if a previous installation was detectedVar ReinstallPageCheckPage custom PageReinstall PageLeaveReinstall; Find a previous WiX installation and set $R6 to its uninstall registry key, or to "" if none.;; A WiX installer stores the installation info in registry; using a UUID and so we have to loop through all keys under; `HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall`; and check if `DisplayName` and `Publisher` keys match ${PRODUCTNAME} and ${MANUFACTURER};; This has a potential issue that there maybe another installation that matches; our ${PRODUCTNAME} and ${MANUFACTURER} but wasn't installed by our WiX installer,; however, this should be fine since the user will have to confirm the uninstallation; and they can chose to abort it if doesn't make sense.Function FindWixInstall StrCpy $R6 "" StrCpy $0 0 wix_loop: EnumRegKey $1 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" $0 StrCmp $1 "" wix_loop_done ; Exit loop if there is no more keys to loop on IntOp $0 $0 + 1 ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$1" "DisplayName" ReadRegStr $R1 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$1" "Publisher" StrCmp "$R0$R1" "${PRODUCTNAME}${MANUFACTURER}" 0 wix_loop ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$1" "UninstallString" ${StrCase} $R1 $R0 "L" ${StrLoc} $R0 $R1 "msiexec" ">" StrCmp $R0 0 0 wix_loop_done StrCpy $R6 "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$1" wix_loop_done:FunctionEndFunction PageReinstall ; Uninstall previous WiX installation if exists. Call FindWixInstall ${If} $R6 != "" StrCpy $WixMode 1 Goto compare_version ${EndIf} ; Check if there is an existing installation, if not, abort the reinstall page ReadRegStr $R0 SHCTX "${UNINSTKEY}" "" ReadRegStr $R1 SHCTX "${UNINSTKEY}" "UninstallString" ${IfThen} "$R0$R1" == "" ${|} Abort ${|} ; Compare this installar version with the existing installation ; and modify the messages presented to the user accordingly compare_version: StrCpy $R4 "$(older)" ${If} $WixMode = 1 ReadRegStr $R0 HKLM "$R6" "DisplayVersion" ${Else} ReadRegStr $R0 SHCTX "${UNINSTKEY}" "DisplayVersion" ${EndIf} ${IfThen} $R0 == "" ${|} StrCpy $R4 "$(unknown)" ${|} nsis_tauri_utils::SemverCompare "${VERSION}" $R0 Pop $R0 ; Read the install choice header through $R5 so a custom language file that only ; defines the misspelled `choowHowToInstall` still shows its own text ; TODO: remove the `choowHowToInstall` fallback in a future major version StrCpy $R5 "$(chooseHowToInstall)" ${IfThen} $R5 == "" ${|} StrCpy $R5 "$(choowHowToInstall)" ${|} ; Reinstalling the same version ${If} $R0 = 0 StrCpy $R1 "$(alreadyInstalledLong)" StrCpy $R2 "$(addOrReinstall)" StrCpy $R3 "$(uninstallApp)" MUI_HEADER_TEXT "$(alreadyInstalled)" "$(chooseMaintenanceOption)" ; Upgrading ${ElseIf} $R0 = 1 StrCpy $R1 "$(olderOrUnknownVersionInstalled)" StrCpy $R2 "$(uninstallBeforeInstalling)" StrCpy $R3 "$(dontUninstall)" MUI_HEADER_TEXT "$(alreadyInstalled)" "$R5" ; Downgrading ${ElseIf} $R0 = -1 StrCpy $R1 "$(newerVersionInstalled)" StrCpy $R2 "$(uninstallBeforeInstalling)" "${ALLOWDOWNGRADES}" == "true" StrCpy $R3 "$(dontUninstall)" StrCpy $R3 "$(dontUninstallDowngrade)" MUI_HEADER_TEXT "$(alreadyInstalled)" "$R5" ${Else} Abort ${EndIf} ; Skip showing the page if passive ; ; Note that we don't call this earlier at the beginning ; of this function because we need to populate some variables ; related to current installed version if detected and whether ; we are downgrading or not. ${If} $PassiveMode = 1 Call PageLeaveReinstall ${Else} nsDialogs::Create 1018 Pop $R4 ${IfThen} $(^RTL) = 1 ${|} nsDialogs::SetRTL $(^RTL) ${|} ${NSD_CreateLabel} 0 0 100% 24u $R1 Pop $R1 ${NSD_CreateRadioButton} 30u 50u -30u 8u $R2 Pop $R2 ${NSD_OnClick} $R2 PageReinstallUpdateSelection ${NSD_CreateRadioButton} 30u 70u -30u 8u $R3 Pop $R3 ; Disable this radio button if downgrading and downgrades are disabled "${ALLOWDOWNGRADES}" == "false" ${IfThen} $R0 = -1 ${|} EnableWindow $R3 0 ${|} ${NSD_OnClick} $R3 PageReinstallUpdateSelection ; Check the first radio button if this the first time ; we enter this page or if the second button wasn't ; selected the last time we were on this page ${If} $ReinstallPageCheck <> 2 SendMessage $R2 ${BM_SETCHECK} ${BST_CHECKED} 0 ${Else} SendMessage $R3 ${BM_SETCHECK} ${BST_CHECKED} 0 ${EndIf} ${NSD_SetFocus} $R2 nsDialogs::Show ${EndIf}FunctionEndFunction PageReinstallUpdateSelection ${NSD_GetState} $R2 $R1 ${If} $R1 == ${BST_CHECKED} StrCpy $ReinstallPageCheck 1 ${Else} StrCpy $ReinstallPageCheck 2 ${EndIf}FunctionEndFunction PageLeaveReinstall ${NSD_GetState} $R2 $R1 ; If migrating from Wix, always uninstall ${If} $WixMode = 1 Goto reinst_uninstall ${EndIf} ; In update mode, always proceeds without uninstalling ${If} $UpdateMode = 1 Goto reinst_done ${EndIf} ; juicewrld.io: one click installs over any version, never uninstalling first (two progress windows for one install). ${If} $PassiveMode = 1 Goto reinst_done ${EndIf} ; $R0 holds whether same(0)/upgrading(1)/downgrading(-1) version ; $R1 holds the radio buttons state: ; 1 => first choice was selected ; 0 => second choice was selected ${If} $R0 = 0 ; Same version, proceed ${If} $R1 = 1 ; User chose to add/reinstall Goto reinst_done ${Else} ; User chose to uninstall Goto reinst_uninstall ${EndIf} ${ElseIf} $R0 = 1 ; Upgrading ${If} $R1 = 1 ; User chose to uninstall Goto reinst_uninstall ${Else} Goto reinst_done ; User chose NOT to uninstall ${EndIf} ${ElseIf} $R0 = -1 ; Downgrading ${If} $R1 = 1 ; User chose to uninstall Goto reinst_uninstall ${Else} Goto reinst_done ; User chose NOT to uninstall ${EndIf} ${EndIf} reinst_uninstall: HideWindow ClearErrors ${If} $WixMode = 1 ReadRegStr $R1 HKLM "$R6" "UninstallString" ExecWait '$R1' $0 ${Else} ReadRegStr $4 SHCTX "${MANUPRODUCTKEY}" "" ReadRegStr $R1 SHCTX "${UNINSTKEY}" "UninstallString" ${IfThen} $UpdateMode = 1 ${|} StrCpy $R1 "$R1 /UPDATE" ${|} ; append /UPDATE ${IfThen} $PassiveMode = 1 ${|} StrCpy $R1 "$R1 /P" ${|} ; append /P StrCpy $R1 "$R1 _?=$4" ; append uninstall directory ExecWait '$R1' $0 ${EndIf} BringToFront ${IfThen} ${Errors} ${|} StrCpy $0 2 ${|} ; ExecWait failed, set fake exit code ${If} $0 <> 0 ${OrIf} ${FileExists} "$INSTDIR\${MAINBINARYNAME}.exe" ; User cancelled wix uninstaller? return to select un/reinstall page ${If} $WixMode = 1 ${AndIf} $0 = 1602 Abort ${EndIf} ; User cancelled NSIS uninstaller? return to select un/reinstall page ${If} $0 = 1 Abort ${EndIf} ; Other errors? show generic error message and return to select un/reinstall page MessageBox MB_ICONEXCLAMATION "$(unableToUninstall)" Abort ${EndIf} ; The NSIS uninstaller was run in place (`_?=`), so it cannot delete itself ; and the install directory, clean them up here once the uninstall succeeded ; https://nsis.sourceforge.io/Docs/Chapter3.html#:~:text=path%20contains%20spaces.-,3.2.3%20Examples,-installer.exe%20/NCRC ${If} $WixMode = 0 ${AndIf} $4 != "" Delete "$4\uninstall.exe" RMDir "$4" ${EndIf} reinst_done:FunctionEnd; 5. Choose install directory page MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive MUI_PAGE_DIRECTORY; 6. Start menu shortcut pageVar AppStartMenuFolder "${STARTMENUFOLDER}" != "" MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive MUI_STARTMENUPAGE_DEFAULTFOLDER "${STARTMENUFOLDER}" MUI_PAGE_CUSTOMFUNCTION_PRE Skip MUI_PAGE_STARTMENU Application $AppStartMenuFolder; 7. Installation page MUI_PAGE_INSTFILES; 8. Finish page;; Don't auto jump to finish page after installation page,; because the installation page has useful info that can be used debug any issues with the installer. MUI_FINISHPAGE_NOAUTOCLOSE; Use show readme button in the finish page as a button create a desktop shortcut MUI_FINISHPAGE_SHOWREADME MUI_FINISHPAGE_SHOWREADME_TEXT "$(createDesktop)" MUI_FINISHPAGE_SHOWREADME_FUNCTION CreateOrUpdateDesktopShortcut; Show run app after installation. MUI_FINISHPAGE_RUN MUI_FINISHPAGE_RUN_FUNCTION RunMainBinary MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive MUI_PAGE_FINISHFunction RunMainBinary nsis_tauri_utils::RunAsUser "$INSTDIR\${MAINBINARYNAME}.exe" ""FunctionEnd; Uninstaller Pages; 1. Confirm uninstall pageVar DeleteAppDataCheckboxVar DeleteAppDataCheckboxState /ifndef WS_EX_LAYOUTRTL 0x00400000 MUI_PAGE_CUSTOMFUNCTION_SHOW un.ConfirmShowFunction un.ConfirmShow ; Add add a `Delete app data` check box ; $1 inner dialog HWND ; $2 window DPI ; $3 style ; $4 x ; $5 y ; $6 width ; $7 height FindWindow $1 "#32770" "" $HWNDPARENT ; Find inner dialog System::Call "user32::GetDpiForWindow(p r1) i .r2" ${If} $(^RTL) = 1 StrCpy $3 "${__NSD_CheckBox_EXSTYLE} | ${WS_EX_LAYOUTRTL}" IntOp $4 50 * $2 ${Else} StrCpy $3 "${__NSD_CheckBox_EXSTYLE}" IntOp $4 0 * $2 ${EndIf} IntOp $5 100 * $2 IntOp $6 400 * $2 IntOp $7 25 * $2 IntOp $4 $4 / 96 IntOp $5 $5 / 96 IntOp $6 $6 / 96 IntOp $7 $7 / 96 System::Call 'user32::CreateWindowEx(i r3, w "${__NSD_CheckBox_CLASS}", w "$(deleteAppData)", i ${__NSD_CheckBox_STYLE}, i r4, i r5, i r6, i r7, p r1, i0, i0, i0) i .s' Pop $DeleteAppDataCheckbox SendMessage $HWNDPARENT ${WM_GETFONT} 0 0 $1 SendMessage $DeleteAppDataCheckbox ${WM_SETFONT} $1 1FunctionEnd MUI_PAGE_CUSTOMFUNCTION_LEAVE un.ConfirmLeaveFunction un.ConfirmLeave SendMessage $DeleteAppDataCheckbox ${BM_GETCHECK} 0 0 $DeleteAppDataCheckboxStateFunctionEnd MUI_PAGE_CUSTOMFUNCTION_PRE un.SkipIfPassive MUI_UNPAGE_CONFIRM; 2. Uninstalling Page MUI_UNPAGE_INSTFILES;Languages; PageReinstall reads the misspelled `choowHowToInstall` as a fallback, and makensis warns; about a language string that is read but never set, so default it to an empty string for; every language. This runs before the language files are included, so a custom language; file that only defines the old spelling overrides the default and the fallback shows its; text. `0` as the language id means the language inserted right above.; TODO: remove the `choowHowToInstall` fallback in a future major version{{#each languages}} MUI_LANGUAGE "{{this}}"LangString choowHowToInstall 0 ""{{/each}} MUI_RESERVEFILE_LANGDLL{{#each language_files}} "{{this}}"{{/each}}Function .onInit ${GetOptions} $CMDLINE "/P" $PassiveMode ${IfNot} ${Errors} StrCpy $PassiveMode 1 ${EndIf} ${GetOptions} $CMDLINE "/NS" $NoShortcutMode ${IfNot} ${Errors} StrCpy $NoShortcutMode 1 ${EndIf} ${GetOptions} $CMDLINE "/UPDATE" $UpdateMode ${IfNot} ${Errors} StrCpy $UpdateMode 1 ${EndIf} ; juicewrld.io: one click. No pages, whatever the command line: what /P does. StrCpy $PassiveMode 1 "${DISPLAYLANGUAGESELECTOR}" == "true" MUI_LANGDLL_DISPLAY SetContext ; juicewrld.io: an update with nothing installed is the portable exe's: a first install, shortcuts and all. ${If} $UpdateMode = 1 ReadRegStr $R0 SHCTX "${UNINSTKEY}" "UninstallString" ${IfThen} $R0 == "" ${|} StrCpy $UpdateMode 0 ${|} ${EndIf} ${If} $INSTDIR == "${PLACEHOLDER_INSTALL_DIR}" ; Set default install location "${INSTALLMODE}" == "perMachine" ${If} ${RunningX64} "${ARCH}" == "x64" StrCpy $INSTDIR "$PROGRAMFILES64\${PRODUCTNAME}" if "${ARCH}" == "arm64" StrCpy $INSTDIR "$PROGRAMFILES64\${PRODUCTNAME}" StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCTNAME}" ${Else} StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCTNAME}" ${EndIf} if "${INSTALLMODE}" == "currentUser" StrCpy $INSTDIR "$LOCALAPPDATA\${PRODUCTNAME}" Call RestorePreviousInstallLocation ${EndIf} "${INSTALLMODE}" == "both" MULTIUSER_INIT ; Abort downgrades if they are disabled, in the modes that skip the reinstall page choice: ; silent, passive and update "${ALLOWDOWNGRADES}" == "false" ${If} ${Silent} ${OrIf} $PassiveMode = 1 ${OrIf} $UpdateMode = 1 ; Compare with the same installation the reinstall page would: a WiX one first Call FindWixInstall ${If} $R6 != "" ReadRegStr $R0 HKLM "$R6" "DisplayVersion" ${Else} ReadRegStr $R0 SHCTX "${UNINSTKEY}" "DisplayVersion" ${EndIf} nsis_tauri_utils::SemverCompare "${VERSION}" $R0 Pop $R0 ; If downgrading ${If} $R0 = -1 ${If} ${Silent} System::Call 'kernel32::AttachConsole(i -1)i.r0' ${If} $0 <> 0 System::Call 'kernel32::GetStdHandle(i -11)i.r0' System::call 'kernel32::SetConsoleTextAttribute(i r0, i 0x0004)' ; set red color FileWrite $0 "$(silentDowngrades)" ${EndIf} ${Else} MessageBox MB_ICONSTOP "$(silentDowngrades)" ${EndIf} Abort ${EndIf} ${EndIf} FunctionEndSection WebView2 ; Check if Webview2 is already installed and skip this section ${If} ${RunningX64} ReadRegStr $4 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\${WEBVIEW2APPGUID}" "pv" ${Else} ReadRegStr $4 HKLM "SOFTWARE\Microsoft\EdgeUpdate\Clients\${WEBVIEW2APPGUID}" "pv" ${EndIf} ${If} $4 == "" ReadRegStr $4 HKCU "SOFTWARE\Microsoft\EdgeUpdate\Clients\${WEBVIEW2APPGUID}" "pv" ${EndIf} ${If} $4 == "" ; Webview2 installation ; ; Skip if updating ${If} $UpdateMode <> 1 "${INSTALLWEBVIEW2MODE}" == "downloadBootstrapper" Delete "$TEMP\MicrosoftEdgeWebview2Setup.exe" DetailPrint "$(webview2Downloading)" NSISdl::download "https://go.microsoft.com/fwlink/p/?LinkId=2124703" "$TEMP\MicrosoftEdgeWebview2Setup.exe" Pop $0 ${If} $0 == "success" DetailPrint "$(webview2DownloadSuccess)" ${Else} DetailPrint "$(webview2DownloadError)" Abort "$(webview2AbortError)" ${EndIf} StrCpy $6 "$TEMP\MicrosoftEdgeWebview2Setup.exe" Goto install_webview2 "${INSTALLWEBVIEW2MODE}" == "embedBootstrapper" Delete "$TEMP\MicrosoftEdgeWebview2Setup.exe" File "/oname=$TEMP\MicrosoftEdgeWebview2Setup.exe" "${WEBVIEW2BOOTSTRAPPERPATH}" DetailPrint "$(installingWebview2)" StrCpy $6 "$TEMP\MicrosoftEdgeWebview2Setup.exe" Goto install_webview2 "${INSTALLWEBVIEW2MODE}" == "offlineInstaller" Delete "$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe" File "/oname=$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe" "${WEBVIEW2INSTALLERPATH}" DetailPrint "$(installingWebview2)" StrCpy $6 "$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe" Goto install_webview2 Goto webview2_done install_webview2: DetailPrint "$(installingWebview2)" ; $6 holds the path to the webview2 installer ExecWait "$6 ${WEBVIEW2INSTALLERARGS} /install" $1 ${If} $1 = 0 DetailPrint "$(webview2InstallSuccess)" ${Else} DetailPrint "$(webview2InstallError)" Abort "$(webview2AbortError)" ${EndIf} webview2_done: ${EndIf} ${Else} "${MINIMUMWEBVIEW2VERSION}" != "" ${VersionCompare} "${MINIMUMWEBVIEW2VERSION}" "$4" $R0 ${If} $R0 = 1 update_webview: DetailPrint "$(installingWebview2)" ${If} ${RunningX64} ReadRegStr $R1 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate" "path" ${Else} ReadRegStr $R1 HKLM "SOFTWARE\Microsoft\EdgeUpdate" "path" ${EndIf} ${If} $R1 == "" ReadRegStr $R1 HKCU "SOFTWARE\Microsoft\EdgeUpdate" "path" ${EndIf} ${If} $R1 != "" ; Chromium updater docs: https://source.chromium.org/chromium/chromium/src/+/main:docs/updater/user_manual.md ; Modified from "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft EdgeWebView\ModifyPath" ExecWait `"$R1" /install appguid=${WEBVIEW2APPGUID}&needsadmin=true` $1 ${If} $1 = 0 DetailPrint "$(webview2InstallSuccess)" ${Else} MessageBox MB_ICONEXCLAMATION|MB_ABORTRETRYIGNORE "$(webview2InstallError)" IDIGNORE ignore IDRETRY update_webview Quit ignore: ${EndIf} ${EndIf} ${EndIf} ${EndIf}SectionEndSection Install SetOutPath $INSTDIR NSIS_HOOK_PREINSTALL NSIS_HOOK_PREINSTALL CheckIfAppIsRunning "$INSTDIR\${MAINBINARYNAME}.exe" "${PRODUCTNAME}" ; juicewrld.io: the portable exe running from elsewhere holds the single instance, so the app this opens would hand over ; to it and quit. Close it as well. nsis_tauri_utils::FindProcessCurrentUser "${MAINBINARYNAME}.exe" Pop $R0 ${If} $R0 = 0 nsis_tauri_utils::KillProcessCurrentUser "${MAINBINARYNAME}.exe" Pop $R0 Sleep 500 ${EndIf} ; Copy main executable File "${MAINBINARYSRCPATH}" ; Copy resources {{#each resources_dirs}} CreateDirectory "$INSTDIR\\{{this}}" {{/each}} {{#each resources}} File /a "/oname={{this.[1]}}" "{{no-escape @key}}" {{/each}} ; Copy external binaries {{#each binaries}} File /a "/oname={{this}}" "{{no-escape @key}}" {{/each}} ; Create file associations {{#each file_associations as |association| ~}} {{#each association.ext as |ext| ~}} APP_ASSOCIATE "{{ext}}" "{{or association.name ext}}" "{{association-description association.description ext}}" "$\"$INSTDIR\${MAINBINARYNAME}.exe$\",0" "Open with ${PRODUCTNAME}" "$\"$INSTDIR\${MAINBINARYNAME}.exe$\" $\"%1$\"" {{/each}} {{/each}} ; Register deep links {{#each deep_link_protocols as |protocol| ~}} WriteRegStr SHCTX "Software\Classes\\{{protocol}}" "URL Protocol" "" WriteRegStr SHCTX "Software\Classes\\{{protocol}}" "" "URL:${BUNDLEID} protocol" WriteRegStr SHCTX "Software\Classes\\{{protocol}}\DefaultIcon" "" "$\"$INSTDIR\${MAINBINARYNAME}.exe$\",0" WriteRegStr SHCTX "Software\Classes\\{{protocol}}\shell\open\command" "" "$\"$INSTDIR\${MAINBINARYNAME}.exe$\" $\"%1$\"" {{/each}} ; Create uninstaller WriteUninstaller "$INSTDIR\uninstall.exe" ; Save $INSTDIR in registry for future installations WriteRegStr SHCTX "${MANUPRODUCTKEY}" "" $INSTDIR "${INSTALLMODE}" == "both" ; Save install mode to be selected by default for the next installation such as updating ; or when uninstalling WriteRegStr SHCTX "${UNINSTKEY}" $MultiUser.InstallMode 1 ; Remove old main binary if it doesn't match new main binary name ReadRegStr $OldMainBinaryName SHCTX "${UNINSTKEY}" "MainBinaryName" ${If} $OldMainBinaryName != "" ${AndIf} $OldMainBinaryName != "${MAINBINARYNAME}.exe" Delete "$INSTDIR\$OldMainBinaryName" ${EndIf} ; Save current MAINBINARYNAME for future updates WriteRegStr SHCTX "${UNINSTKEY}" "MainBinaryName" "${MAINBINARYNAME}.exe" ; Registry information for add/remove programs WriteRegStr SHCTX "${UNINSTKEY}" "DisplayName" "${PRODUCTNAME}" WriteRegStr SHCTX "${UNINSTKEY}" "DisplayIcon" "$\"$INSTDIR\${MAINBINARYNAME}.exe$\"" WriteRegStr SHCTX "${UNINSTKEY}" "DisplayVersion" "${VERSION}" WriteRegStr SHCTX "${UNINSTKEY}" "Publisher" "${MANUFACTURER}" WriteRegStr SHCTX "${UNINSTKEY}" "InstallLocation" "$\"$INSTDIR$\"" WriteRegStr SHCTX "${UNINSTKEY}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\"" WriteRegDWORD SHCTX "${UNINSTKEY}" "NoModify" "1" WriteRegDWORD SHCTX "${UNINSTKEY}" "NoRepair" "1" ${GetSize} "$INSTDIR" "/M=uninstall.exe /S=0K /G=0" $0 $1 $2 IntOp $0 $0 + ${ESTIMATEDSIZE} IntFmt $0 "0x%08X" $0 WriteRegDWORD SHCTX "${UNINSTKEY}" "EstimatedSize" "$0" "${HOMEPAGE}" != "" WriteRegStr SHCTX "${UNINSTKEY}" "URLInfoAbout" "${HOMEPAGE}" WriteRegStr SHCTX "${UNINSTKEY}" "URLUpdateInfo" "${HOMEPAGE}" WriteRegStr SHCTX "${UNINSTKEY}" "HelpLink" "${HOMEPAGE}" ; Create start menu shortcut MUI_STARTMENU_WRITE_BEGIN Application Call CreateOrUpdateStartMenuShortcut MUI_STARTMENU_WRITE_END ; Create desktop shortcut for silent and passive installers ; because finish page will be skipped ${If} $PassiveMode = 1 ${OrIf} ${Silent} Call CreateOrUpdateDesktopShortcut ${EndIf} NSIS_HOOK_POSTINSTALL NSIS_HOOK_POSTINSTALL ; Auto close this page for passive mode ${If} $PassiveMode = 1 SetAutoClose true ${EndIf}SectionEndFunction .onInstSuccess ; juicewrld.io: a double-click opens the app when it's done; an update (or a silent install) only with /R. Never with ; /ARGS: the old process's arguments are a juicewrld:// link at most, already handled. ${GetOptions} $CMDLINE "/R" $R0 ${IfNot} ${Errors} nsis_tauri_utils::RunAsUser "$INSTDIR\${MAINBINARYNAME}.exe" "" ${ElseIf} $UpdateMode <> 1 ${AndIfNot} ${Silent} nsis_tauri_utils::RunAsUser "$INSTDIR\${MAINBINARYNAME}.exe" "" ${EndIf}FunctionEndFunction un.onInit SetContext "${INSTALLMODE}" == "both" MULTIUSER_UNINIT MUI_UNGETLANGUAGE ${GetOptions} $CMDLINE "/P" $PassiveMode ${IfNot} ${Errors} StrCpy $PassiveMode 1 ${EndIf} ${GetOptions} $CMDLINE "/UPDATE" $UpdateMode ${IfNot} ${Errors} StrCpy $UpdateMode 1 ${EndIf}FunctionEndSection Uninstall NSIS_HOOK_PREUNINSTALL NSIS_HOOK_PREUNINSTALL CheckIfAppIsRunning "$INSTDIR\${MAINBINARYNAME}.exe" "${PRODUCTNAME}" ; Delete the app directory and its content from disk ; Copy main executable Delete "$INSTDIR\${MAINBINARYNAME}.exe" ; Delete resources {{#each resources}} Delete "$INSTDIR\\{{this.[1]}}" {{/each}} ; Delete external binaries {{#each binaries}} Delete "$INSTDIR\\{{this}}" {{/each}} ; Delete app associations {{#each file_associations as |association| ~}} {{#each association.ext as |ext| ~}} APP_UNASSOCIATE "{{ext}}" "{{or association.name ext}}" {{/each}} {{/each}} ; Delete deep links {{#each deep_link_protocols as |protocol| ~}} ReadRegStr $R7 SHCTX "Software\Classes\\{{protocol}}\shell\open\command" "" ${If} $R7 == "$\"$INSTDIR\${MAINBINARYNAME}.exe$\" $\"%1$\"" DeleteRegKey SHCTX "Software\Classes\\{{protocol}}" ${EndIf} {{/each}} ; Delete uninstaller Delete "$INSTDIR\uninstall.exe" {{#each resources_ancestors}} RMDir /REBOOTOK "$INSTDIR\\{{this}}" {{/each}} RMDir "$INSTDIR" ; Remove shortcuts if not updating ${If} $UpdateMode <> 1 DeleteAppUserModelId ; Remove start menu shortcut MUI_STARTMENU_GETFOLDER Application $AppStartMenuFolder IsShortcutTarget "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" Pop $0 ${If} $0 = 1 UnpinShortcut "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" Delete "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" RMDir "$SMPROGRAMS\$AppStartMenuFolder" ${EndIf} IsShortcutTarget "$SMPROGRAMS\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" Pop $0 ${If} $0 = 1 UnpinShortcut "$SMPROGRAMS\${PRODUCTNAME}.lnk" Delete "$SMPROGRAMS\${PRODUCTNAME}.lnk" ${EndIf} ; Remove desktop shortcuts IsShortcutTarget "$DESKTOP\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" Pop $0 ${If} $0 = 1 UnpinShortcut "$DESKTOP\${PRODUCTNAME}.lnk" Delete "$DESKTOP\${PRODUCTNAME}.lnk" ${EndIf} ${EndIf} ; Remove registry information for add/remove programs "${INSTALLMODE}" == "both" DeleteRegKey SHCTX "${UNINSTKEY}" if "${INSTALLMODE}" == "perMachine" DeleteRegKey HKLM "${UNINSTKEY}" DeleteRegKey HKCU "${UNINSTKEY}" ; Removes the Autostart entry for ${PRODUCTNAME} from the HKCU Run key if it exists. ; This ensures the program does not launch automatically after uninstallation if it exists. ; If it doesn't exist, it does nothing. ; We do this when not updating (to preserve the registry value on updates) ${If} $UpdateMode <> 1 DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "${PRODUCTNAME}" ${EndIf} ; Delete app data if the checkbox is selected ; and if not updating ${If} $DeleteAppDataCheckboxState = 1 ${AndIf} $UpdateMode <> 1 ; Clear the install location $INSTDIR from registry DeleteRegKey SHCTX "${MANUPRODUCTKEY}" DeleteRegKey /ifempty SHCTX "${MANUKEY}" ; Clear the install language from registry DeleteRegValue HKCU "${MANUPRODUCTKEY}" "Installer Language" DeleteRegKey /ifempty HKCU "${MANUPRODUCTKEY}" DeleteRegKey /ifempty HKCU "${MANUKEY}" SetShellVarContext current RmDir /r "$APPDATA\${BUNDLEID}" RmDir /r "$LOCALAPPDATA\${BUNDLEID}" ${EndIf} NSIS_HOOK_POSTUNINSTALL NSIS_HOOK_POSTUNINSTALL ; Auto close if passive mode or updating ${If} $PassiveMode = 1 ${OrIf} $UpdateMode = 1 SetAutoClose true ${EndIf}SectionEndFunction RestorePreviousInstallLocation ReadRegStr $4 SHCTX "${MANUPRODUCTKEY}" "" StrCmp $4 "" +2 0 StrCpy $INSTDIR $4FunctionEndFunction Skip AbortFunctionEndFunction SkipIfPassive ${IfThen} $PassiveMode = 1 ${|} Abort ${|}FunctionEndFunction un.SkipIfPassive ${IfThen} $PassiveMode = 1 ${|} Abort ${|}FunctionEndFunction CreateOrUpdateStartMenuShortcut ; We used to use product name as MAINBINARYNAME ; migrate old shortcuts to target the new MAINBINARYNAME StrCpy $R0 0 IsShortcutTarget "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" "$INSTDIR\$OldMainBinaryName" Pop $0 ${If} $0 = 1 SetShortcutTarget "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" StrCpy $R0 1 ${EndIf} IsShortcutTarget "$SMPROGRAMS\${PRODUCTNAME}.lnk" "$INSTDIR\$OldMainBinaryName" Pop $0 ${If} $0 = 1 SetShortcutTarget "$SMPROGRAMS\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" StrCpy $R0 1 ${EndIf} ${If} $R0 = 1 Return ${EndIf} ; Skip creating shortcut if in update mode or no shortcut mode ; but always create if migrating from wix ${If} $WixMode = 0 ${If} $UpdateMode = 1 ${OrIf} $NoShortcutMode = 1 Return ${EndIf} ${EndIf} "${STARTMENUFOLDER}" != "" CreateDirectory "$SMPROGRAMS\$AppStartMenuFolder" CreateShortcut "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" SetLnkAppUserModelId "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" CreateShortcut "$SMPROGRAMS\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" SetLnkAppUserModelId "$SMPROGRAMS\${PRODUCTNAME}.lnk" FunctionEndFunction CreateOrUpdateDesktopShortcut ; We used to use product name as MAINBINARYNAME ; migrate old shortcuts to target the new MAINBINARYNAME IsShortcutTarget "$DESKTOP\${PRODUCTNAME}.lnk" "$INSTDIR\$OldMainBinaryName" Pop $0 ${If} $0 = 1 SetShortcutTarget "$DESKTOP\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" Return ${EndIf} ; Skip creating shortcut if in update mode or no shortcut mode ; but always create if migrating from wix ${If} $WixMode = 0 ${If} $UpdateMode = 1 ${OrIf} $NoShortcutMode = 1 Return ${EndIf} ${EndIf} CreateShortcut "$DESKTOP\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" SetLnkAppUserModelId "$DESKTOP\${PRODUCTNAME}.lnk"FunctionEnd