Browse Source

feat(nsis): restart app after updating, closes #6955 (#6987)

* feat(nsis): restart app after updating, closes #6955

* Apply suggestions from code review
Amr Bashir 2 years ago
parent
commit
cd3846c8ce

+ 5 - 0
.changes/nsis-install-mode-args.md

@@ -0,0 +1,5 @@
+---
+'tauri-utils': 'patch'
+---
+
+Add `WindowsUpdateInstallMode::nsis_args`

+ 6 - 0
.changes/nsis-updater-restart.md

@@ -0,0 +1,6 @@
+---
+'tauri': 'minor'
+'cli.rs': 'minor'
+---
+
+Restart the app after the NSIS updater is finished.

+ 2 - 2
core/tauri-config-schema/schema.json

@@ -2808,14 +2808,14 @@
           ]
         },
         {
-          "description": "The quiet mode means there's no user interaction required. Requires admin privileges if the installer does (WiX).",
+          "description": "The quiet mode means there's no user interaction required. Requires admin privileges if the installer does.",
           "type": "string",
           "enum": [
             "quiet"
           ]
         },
         {
-          "description": "Specifies unattended mode, which means the installation only shows a progress bar.",
+          "description": "Specifies unattended mode, which means the installation only shows a progress bar. **msi (Wix) Only**",
           "type": "string",
           "enum": [
             "passive"

+ 10 - 2
core/tauri-utils/src/config.rs

@@ -2479,9 +2479,9 @@ pub enum WindowsUpdateInstallMode {
   /// Specifies there's a basic UI during the installation process, including a final dialog box at the end.
   BasicUi,
   /// The quiet mode means there's no user interaction required.
-  /// Requires admin privileges if the installer does (WiX).
+  /// Requires admin privileges if the installer does.
   Quiet,
-  /// Specifies unattended mode, which means the installation only shows a progress bar.
+  /// Specifies unattended mode, which means the installation only shows a progress bar. **msi (Wix) Only**
   Passive,
   // to add more modes, we need to check if the updater relaunch makes sense
   // i.e. for a full UI mode, the user can also mark the installer to start the app
@@ -2496,6 +2496,14 @@ impl WindowsUpdateInstallMode {
       Self::Passive => &["/passive"],
     }
   }
+
+  /// Returns the associated nsis arguments.
+  pub fn nsis_args(&self) -> &'static [&'static str] {
+    match self {
+      Self::Quiet => &["/S", "/R"],
+      _ => &[],
+    }
+  }
 }
 
 impl Display for WindowsUpdateInstallMode {

+ 1 - 2
core/tauri/src/updater/core.rs

@@ -739,7 +739,7 @@ fn copy_files_and_run<R: Read + Seek>(
       if crate::utils::config::WindowsUpdateInstallMode::Quiet
         == config.tauri.updater.windows.install_mode
       {
-        installer.arg("/S");
+        installer.args(config.tauri.updater.windows.install_mode.nsis_args());
       }
       installer.args(&config.tauri.updater.windows.installer_args);
 
@@ -802,7 +802,6 @@ fn copy_files_and_run<R: Read + Seek>(
         .updater
         .windows
         .install_mode
-        .clone()
         .msiexec_args()
         .iter()
         .map(|p| p.to_string())

+ 11 - 0
tooling/bundler/src/bundle/windows/templates/installer.nsi

@@ -472,6 +472,17 @@ Section Install
 
 SectionEnd
 
+Var Restart
+Function .onInstSuccess
+  ; Check for `/R` flag only in silent installer because
+  ; gui installer has a toggle for the user to restart the app
+  IfSilent 0 done
+    ${GetOptions} $CMDLINE "/R" $Restart
+    IfErrors done 0 ; if errors were found then `/R` wasn't passed, so we skip restarting
+      Exec '"$INSTDIR\${MAINBINARYNAME}.exe"'
+  done:
+FunctionEnd
+
 Function un.onInit
   !if "${INSTALLMODE}" == "both"
     !insertmacro MULTIUSER_UNINIT

+ 2 - 2
tooling/cli/schema.json

@@ -2808,14 +2808,14 @@
           ]
         },
         {
-          "description": "The quiet mode means there's no user interaction required. Requires admin privileges if the installer does (WiX).",
+          "description": "The quiet mode means there's no user interaction required. Requires admin privileges if the installer does.",
           "type": "string",
           "enum": [
             "quiet"
           ]
         },
         {
-          "description": "Specifies unattended mode, which means the installation only shows a progress bar.",
+          "description": "Specifies unattended mode, which means the installation only shows a progress bar. **msi (Wix) Only**",
           "type": "string",
           "enum": [
             "passive"