Skip to content

Commit 0fa7453

Browse files
authored
feat(updater): relaunch on Windows, closes #4220 (#4568)
1 parent dbb8c87 commit 0fa7453

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Configure the updater to relaunch after installing the update on Windows.

core/tauri-utils/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,6 +2130,8 @@ pub enum WindowsUpdateInstallMode {
21302130
Quiet,
21312131
/// Specifies unattended mode, which means the installation only shows a progress bar.
21322132
Passive,
2133+
// to add more modes, we need to check if the updater relaunch makes sense
2134+
// i.e. for a full UI mode, the user can also mark the installer to start the app
21332135
}
21342136

21352137
impl WindowsUpdateInstallMode {

core/tauri/src/updater/core.rs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -784,14 +784,37 @@ fn copy_files_and_run<R: Read + Seek>(
784784
}
785785
}
786786

787-
// restart should be handled by WIX as we exit the process
788-
Command::new("msiexec.exe")
789-
.arg("/i")
790-
.arg(found_path)
791-
.args(msiexec_args)
792-
.arg("/promptrestart")
793-
.spawn()
794-
.expect("installer failed to start");
787+
// we need to wrap the current exe path in quotes for Start-Process
788+
let mut current_exe_arg = std::ffi::OsString::new();
789+
current_exe_arg.push("\"");
790+
current_exe_arg.push(current_exe()?);
791+
current_exe_arg.push("\"");
792+
// run the installer and relaunch the application
793+
let powershell_install_res = Command::new("powershell.exe")
794+
.args(["-NoProfile", "-windowstyle", "hidden"])
795+
.args([
796+
"Start-Process",
797+
"-Wait",
798+
"-FilePath",
799+
"msiexec",
800+
"-ArgumentList",
801+
])
802+
.arg("/i,")
803+
.arg(&found_path)
804+
.arg(format!(", {}, /promptrestart;", msiexec_args.join(", ")))
805+
.arg("Start-Process")
806+
.arg(current_exe_arg)
807+
.spawn();
808+
if powershell_install_res.is_err() {
809+
// fallback to running msiexec directly - relaunch won't be available
810+
// we use this here in case powershell fails in an older machine somehow
811+
let _ = Command::new("msiexec.exe")
812+
.arg("/i")
813+
.arg(found_path)
814+
.args(msiexec_args)
815+
.arg("/promptrestart")
816+
.spawn();
817+
}
795818

796819
exit(0);
797820
}

0 commit comments

Comments
 (0)