Browse Source

feat(NSIS): option to remove user data & uninstaller lang & fix RTL (#6129)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
Amr Bashir 2 years ago
parent
commit
f29c56da8c

+ 2 - 0
tooling/bundler/src/bundle/windows/nsis.rs

@@ -53,6 +53,8 @@ const NSIS_REQUIRED_FILES: &[&str] = &[
   "Include/MUI2.nsh",
   "Include/FileFunc.nsh",
   "Include/x64.nsh",
+  "Include/nsDialogs.nsh",
+  "Include/WinMessages.nsh",
 ];
 #[cfg(not(target_os = "windows"))]
 const NSIS_REQUIRED_FILES: &[&str] = &[

+ 62 - 17
tooling/bundler/src/bundle/windows/templates/installer.nsi

@@ -27,11 +27,13 @@ Var ReinstallPageCheck
 !define WEBVIEW2BOOTSTRAPPERPATH "{{{webview2_bootstrapper_path}}}"
 !define WEBVIEW2INSTALLERPATH "{{{webview2_installer_path}}}"
 !define UNINSTKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}"
+!define MANUPRODUCTKEY "Software\${MANUFACTURER}\${PRODUCTNAME}"
 
 Name "${PRODUCTNAME}"
 OutFile "${OUTFILE}"
 Unicode true
 SetCompressor /SOLID lzma
+
 !if "${PLUGINSPATH}" != ""
     !addplugindir "${PLUGINSPATH}"
 !endif
@@ -53,7 +55,7 @@ SetCompressor /SOLID lzma
   !define MULTIUSER_INSTALLMODEPAGE_SHOWUSERNAME
   !define MULTIUSER_INSTALLMODE_FUNCTION RestorePreviousInstallLocation
   Function RestorePreviousInstallLocation
-    ReadRegStr $4 SHCTX "Software\${MANUFACTURER}\${PRODUCTNAME}" ""
+    ReadRegStr $4 SHCTX "${MANUPRODUCTKEY}" ""
     StrCmp $4 "" +2 0
       StrCpy $INSTDIR $4
   FunctionEnd
@@ -73,19 +75,10 @@ SetCompressor /SOLID lzma
   !define MUI_HEADERIMAGE_BITMAP  "${HEADERIMAGE}"
 !endif
 
-; 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.
-!define MUI_FINISHPAGE_NOAUTOCLOSE
-; Use show readme button in the finish page to create a desktop shortcut
-!define MUI_FINISHPAGE_SHOWREADME
-!define MUI_FINISHPAGE_SHOWREADME_TEXT "$(createDesktop)"
-!define MUI_FINISHPAGE_SHOWREADME_FUNCTION CreateDesktopShortcut
-Function CreateDesktopShortcut
-  CreateShortcut "$DESKTOP\${MAINBINARYNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe"
-  ApplicationID::Set "$DESKTOP\${MAINBINARYNAME}.lnk" "${BUNDLEID}"
-FunctionEnd
-; Show run app after installation.
-!define MUI_FINISHPAGE_RUN "$INSTDIR\${MAINBINARYNAME}.exe"
+; Define registry key to store installer language
+!define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
+!define MUI_LANGDLL_REGISTRY_KEY "${MANUPRODUCTKEY}"
+!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
 
 ; Installer pages, must be ordered as they appear
 !insertmacro MUI_PAGE_WELCOME
@@ -95,6 +88,8 @@ FunctionEnd
 !if "${INSTALLMODE}" == "both"
   !insertmacro MULTIUSER_PAGE_INSTALLMODE
 !endif
+
+; Custom page to ask user if he wants to reinstall/uninstall
 Page custom PageReinstall PageLeaveReinstall
 Function PageReinstall
   ; Check if there is an existing installation, if not, abort the reinstall page
@@ -140,6 +135,9 @@ Function PageReinstall
 
   nsDialogs::Create 1018
   Pop $R4
+  ${If} $(^RTL) == 1
+    nsDialogs::SetRTL $(^RTL)
+  ${EndIf}
 
   ${NSD_CreateLabel} 0 0 100% 24u $R1
   Pop $R1
@@ -191,7 +189,7 @@ Function PageLeaveReinstall
   StrCmp $R1 "1" reinst_done ; Same version, skip to add/reinstall components?
 
   reinst_uninstall:
-    ReadRegStr $4 SHCTX "Software\${MANUFACTURER}\${PRODUCTNAME}" ""
+    ReadRegStr $4 SHCTX "${MANUPRODUCTKEY}" ""
     ReadRegStr $R1 SHCTX "${UNINSTKEY}" "UninstallString"
 
     HideWindow
@@ -221,13 +219,50 @@ Function PageLeaveReinstall
 
   reinst_done:
 FunctionEnd
+
 !insertmacro MUI_PAGE_DIRECTORY
 !insertmacro MUI_PAGE_STARTMENU Application $AppStartMenuFolder
 !insertmacro MUI_PAGE_INSTFILES
+
+; 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.
+!define MUI_FINISHPAGE_NOAUTOCLOSE
+; Use show readme button in the finish page to create a desktop shortcut
+!define MUI_FINISHPAGE_SHOWREADME
+!define MUI_FINISHPAGE_SHOWREADME_TEXT "$(createDesktop)"
+!define MUI_FINISHPAGE_SHOWREADME_FUNCTION CreateDesktopShortcut
+Function CreateDesktopShortcut
+  CreateShortcut "$DESKTOP\${MAINBINARYNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe"
+  ApplicationID::Set "$DESKTOP\${MAINBINARYNAME}.lnk" "${BUNDLEID}"
+FunctionEnd
+; Show run app after installation.
+!define MUI_FINISHPAGE_RUN "$INSTDIR\${MAINBINARYNAME}.exe"
 !insertmacro MUI_PAGE_FINISH
-; Uninstaller pages
+
+; Uninstaller Pages
+Var DeleteAppDataCheckbox
+Var DeleteAppDataCheckboxState
+!define /ifndef WS_EX_LAYOUTRTL         0x00400000
+!define MUI_PAGE_CUSTOMFUNCTION_SHOW un.ConfirmShow
+Function un.ConfirmShow
+    FindWindow $1 "#32770" "" $HWNDPARENT ; Find inner dialog
+    ${If} $(^RTL) == 1
+      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'
+    ${Else}
+      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'
+    ${EndIf}
+    Pop $DeleteAppDataCheckbox
+    SendMessage $HWNDPARENT ${WM_GETFONT} 0 0 $1
+    SendMessage $DeleteAppDataCheckbox ${WM_SETFONT} $1 1
+FunctionEnd
+!define MUI_PAGE_CUSTOMFUNCTION_LEAVE un.ConfirmLeave
+Function un.ConfirmLeave
+    SendMessage $DeleteAppDataCheckbox ${BM_GETCHECK} 0 0 $DeleteAppDataCheckboxState
+FunctionEnd
 !insertmacro MUI_UNPAGE_CONFIRM
+
 !insertmacro MUI_UNPAGE_INSTFILES
+
 ;Languages
 {{#each languages}}
 !insertmacro MUI_LANGUAGE "{{this}}"
@@ -398,7 +433,7 @@ Section Install
   WriteUninstaller "$INSTDIR\uninstall.exe"
 
   ; Save $INSTDIR in registry for future installations
-  WriteRegStr SHCTX "Software\${MANUFACTURER}\${PRODUCTNAME}" "" $INSTDIR
+  WriteRegStr SHCTX "${MANUPRODUCTKEY}" "" $INSTDIR
 
   !if "${INSTALLMODE}" == "both"
     ; Save install mode to be selected by default for the next installation such as updating
@@ -438,6 +473,8 @@ Function un.onInit
   !if "${INSTALLMODE}" == "both"
     !insertmacro MULTIUSER_UNINIT
   !endif
+
+  !insertmacro MUI_UNGETLANGUAGE
 FunctionEnd
 
 Section Uninstall
@@ -462,6 +499,8 @@ Section Uninstall
     DeleteRegKey HKCU "${UNINSTKEY}"
   !endif
 
+  DeleteRegValue HKCU "${MANUPRODUCTKEY}" "Installer Language"
+
   ; Delete the app directory and its content from disk
   ; Copy main executable
   Delete "$INSTDIR\${MAINBINARYNAME}.exe"
@@ -489,5 +528,11 @@ Section Uninstall
 
   ; Remove desktop shortcuts
   Delete "$DESKTOP\${MAINBINARYNAME}.lnk"
+
+  ; Delete app data
+  ${If} $DeleteAppDataCheckboxState == 1
+    RmDir /r "$APPDATA\${BUNDLEID}"
+    RmDir /r "$LOCALAPPDATA\${BUNDLEID}"
+  ${EndIf}
 SectionEnd
 

+ 1 - 0
tooling/bundler/src/bundle/windows/templates/nsis-languages/Arabic.nsh

@@ -24,3 +24,4 @@ LangString webview2DownloadSuccess ${LANG_ARABIC} "تم تنزيل WebView2 boot
 LangString webview2Downloading ${LANG_ARABIC} "يتم تنزيل WebView2 bootstrapper..."
 LangString webview2InstallError ${LANG_ARABIC} "خطأ: فشل فى تنصيب WebView2 بكود $1"
 LangString webview2InstallSuccess ${LANG_ARABIC} "تم تنصيب WebView2 بنجاح"
+LangString deleteAppData ${LANG_ARABIC} "مسح بيانات التطبيق"

+ 1 - 0
tooling/bundler/src/bundle/windows/templates/nsis-languages/English.nsh

@@ -24,3 +24,4 @@ LangString webview2DownloadSuccess ${LANG_ENGLISH} "WebView2 bootstrapper downlo
 LangString webview2Downloading ${LANG_ENGLISH} "Downloading WebView2 bootstrapper..."
 LangString webview2InstallError ${LANG_ENGLISH} "Error: Installing WebView2 failed with exit code $1"
 LangString webview2InstallSuccess ${LANG_ENGLISH} "WebView2 installed successfully"
+LangString deleteAppData ${LANG_ENGLISH} "Delete the application data"

+ 1 - 0
tooling/bundler/src/bundle/windows/templates/nsis-languages/PortugueseBR.nsh

@@ -24,3 +24,4 @@ LangString webview2DownloadSuccess ${LANG_PORTUGUESEBR} "Bootstrapper do WebView
 LangString webview2Downloading ${LANG_PORTUGUESEBR} "Baixando o Bootstrapper do WebView2..."
 LangString webview2InstallError ${LANG_PORTUGUESEBR} "Erro: Instalação do Webview2 falhou com código $1"
 LangString webview2InstallSuccess ${LANG_PORTUGUESEBR} "WebView2 instalado com sucesso"
+LangString deleteAppData ${LANG_PORTUGUESEBR} "Remover dados do programa"

+ 1 - 0
tooling/bundler/src/bundle/windows/templates/nsis-languages/SimpChinese.nsh

@@ -24,3 +24,4 @@ LangString webview2DownloadSuccess ${LANG_SIMPCHINESE} "WebView2 安装程序下
 LangString webview2Downloading ${LANG_SIMPCHINESE} "正在下载 WebView2 安装程序..."
 LangString webview2InstallError ${LANG_SIMPCHINESE} "错误:安装 WebView2 时失败,错误代码:$1"
 LangString webview2InstallSuccess ${LANG_SIMPCHINESE} "成功安装 WebView2"
+LangString deleteAppData ${LANG_SIMPCHINESE} "Delete the application data"

+ 1 - 0
tooling/bundler/src/bundle/windows/templates/nsis-languages/TradChinese.nsh

@@ -24,3 +24,4 @@ LangString webview2DownloadSuccess ${LANG_TRADCHINESE} "WebView2 啟動載入器
 LangString webview2Downloading ${LANG_TRADCHINESE} "正在下載 WebView2 啟動載入器..."
 LangString webview2InstallError ${LANG_TRADCHINESE} "錯誤:WebView2 安裝失敗,錯誤碼 $1"
 LangString webview2InstallSuccess ${LANG_TRADCHINESE} "WebView2 安裝成功"
+LangString deleteAppData ${LANG_TRADCHINESE} "Delete the application data"