fix(core): retain command line arguments on restart, closes #4760 (#4763)

This commit is contained in:
Lucas Fernandes Nogueira 2022-07-25 10:59:24 -03:00 committed by GitHub
parent 6d4945c9f0
commit 6218c31e17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 1 deletions

5
.changes/retain-args.md Normal file
View File

@ -0,0 +1,5 @@
---
"tauri": patch
---
Retain command line arguments in `api::process::restart`.

View File

@ -105,11 +105,14 @@ 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 {
@ -117,6 +120,7 @@ impl Default for Env {
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
@ -139,7 +143,7 @@ impl Default for Env {
}
#[cfg(not(target_os = "linux"))]
{
Self {}
Self { args }
}
}
}

View File

@ -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");
}