Skip to content

Commit

Permalink
fix(core): retain command line arguments on restart, closes #4760 (#4763
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lucasfernog authored Jul 25, 2022
1 parent 6d4945c commit 6218c31
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/retain-args.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Retain command line arguments in `api::process::restart`.
6 changes: 5 additions & 1 deletion core/tauri-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,22 @@ pub struct Env {
/// The APPDIR environment variable.
#[cfg(target_os = "linux")]
pub appdir: Option<std::ffi::OsString>,
/// The command line arguments of the current process.
pub args: Vec<String>,
}

#[allow(clippy::derivable_impls)]
impl Default for Env {
fn default() -> Self {
let args = std::env::args().skip(1).collect();
#[cfg(target_os = "linux")]
{
let env = Self {
#[cfg(target_os = "linux")]
appimage: std::env::var_os("APPIMAGE"),
#[cfg(target_os = "linux")]
appdir: std::env::var_os("APPDIR"),
args,
};
if env.appimage.is_some() || env.appdir.is_some() {
// validate that we're actually running on an AppImage
Expand All @@ -139,7 +143,7 @@ impl Default for Env {
}
#[cfg(not(target_os = "linux"))]
{
Self {}
Self { args }
}
}
}
Expand Down
1 change: 1 addition & 0 deletions core/tauri/src/api/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub fn restart(env: &Env) {

if let Ok(path) = current_binary(env) {
Command::new(path)
.args(&env.args)
.spawn()
.expect("application failed to start");
}
Expand Down

0 comments on commit 6218c31

Please sign in to comment.