Skip to content

Commit

Permalink
feat(updater): relaunch on Windows, closes tauri-apps#4220 (tauri-app…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Jul 3, 2022
1 parent dbb8c87 commit 0fa7453
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changes/windows-updater-relaunch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Configure the updater to relaunch after installing the update on Windows.
2 changes: 2 additions & 0 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2130,6 +2130,8 @@ pub enum WindowsUpdateInstallMode {
Quiet,
/// Specifies unattended mode, which means the installation only shows a progress bar.
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
}

impl WindowsUpdateInstallMode {
Expand Down
39 changes: 31 additions & 8 deletions core/tauri/src/updater/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,14 +784,37 @@ fn copy_files_and_run<R: Read + Seek>(
}
}

// restart should be handled by WIX as we exit the process
Command::new("msiexec.exe")
.arg("/i")
.arg(found_path)
.args(msiexec_args)
.arg("/promptrestart")
.spawn()
.expect("installer failed to start");
// we need to wrap the current exe path in quotes for Start-Process
let mut current_exe_arg = std::ffi::OsString::new();
current_exe_arg.push("\"");
current_exe_arg.push(current_exe()?);
current_exe_arg.push("\"");
// run the installer and relaunch the application
let powershell_install_res = Command::new("powershell.exe")
.args(["-NoProfile", "-windowstyle", "hidden"])
.args([
"Start-Process",
"-Wait",
"-FilePath",
"msiexec",
"-ArgumentList",
])
.arg("/i,")
.arg(&found_path)
.arg(format!(", {}, /promptrestart;", msiexec_args.join(", ")))
.arg("Start-Process")
.arg(current_exe_arg)
.spawn();
if powershell_install_res.is_err() {
// fallback to running msiexec directly - relaunch won't be available
// we use this here in case powershell fails in an older machine somehow
let _ = Command::new("msiexec.exe")
.arg("/i")
.arg(found_path)
.args(msiexec_args)
.arg("/promptrestart")
.spawn();
}

exit(0);
}
Expand Down

0 comments on commit 0fa7453

Please sign in to comment.