Skip to content

Commit 6218c31

Browse files
authored
fix(core): retain command line arguments on restart, closes #4760 (#4763)
1 parent 6d4945c commit 6218c31

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

.changes/retain-args.md

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+
Retain command line arguments in `api::process::restart`.

core/tauri-utils/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,22 @@ pub struct Env {
105105
/// The APPDIR environment variable.
106106
#[cfg(target_os = "linux")]
107107
pub appdir: Option<std::ffi::OsString>,
108+
/// The command line arguments of the current process.
109+
pub args: Vec<String>,
108110
}
109111

110112
#[allow(clippy::derivable_impls)]
111113
impl Default for Env {
112114
fn default() -> Self {
115+
let args = std::env::args().skip(1).collect();
113116
#[cfg(target_os = "linux")]
114117
{
115118
let env = Self {
116119
#[cfg(target_os = "linux")]
117120
appimage: std::env::var_os("APPIMAGE"),
118121
#[cfg(target_os = "linux")]
119122
appdir: std::env::var_os("APPDIR"),
123+
args,
120124
};
121125
if env.appimage.is_some() || env.appdir.is_some() {
122126
// validate that we're actually running on an AppImage
@@ -139,7 +143,7 @@ impl Default for Env {
139143
}
140144
#[cfg(not(target_os = "linux"))]
141145
{
142-
Self {}
146+
Self { args }
143147
}
144148
}
145149
}

core/tauri/src/api/process.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub fn restart(env: &Env) {
8383

8484
if let Ok(path) = current_binary(env) {
8585
Command::new(path)
86+
.args(&env.args)
8687
.spawn()
8788
.expect("application failed to start");
8889
}

0 commit comments

Comments
 (0)