Эх сурвалжийг харах

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

Lucas Fernandes Nogueira 3 жил өмнө
parent
commit
6218c31e17

+ 5 - 0
.changes/retain-args.md

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

+ 5 - 1
core/tauri-utils/src/lib.rs

@@ -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 }
     }
   }
 }

+ 1 - 0
core/tauri/src/api/process.rs

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