Browse Source

refactor!: changed `Env.args` to `Env.args_os` and use `OsString` instead of `String` (#7876)

ref: https://github.com/tauri-apps/tauri/issues/7756
Amr Bashir 1 năm trước cách đây
mục cha
commit
deea943626

+ 5 - 0
.changes/tauri-env-args.md

@@ -0,0 +1,5 @@
+---
+'tauri': 'major:breaking'
+---
+
+Changed `Env.args` to `Env.args_os` and now uses `OsString` instead of `String`

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

@@ -14,6 +14,7 @@
 #![allow(clippy::deprecated_semver)]
 
 use std::{
+  ffi::OsString,
   fmt::Display,
   path::{Path, PathBuf},
 };
@@ -275,13 +276,13 @@ pub struct Env {
   #[cfg(target_os = "linux")]
   pub appdir: Option<std::ffi::OsString>,
   /// The command line arguments of the current process.
-  pub args: Vec<String>,
+  pub args_os: Vec<OsString>,
 }
 
 #[allow(clippy::derivable_impls)]
 impl Default for Env {
   fn default() -> Self {
-    let args = std::env::args().skip(1).collect();
+    let args_os = std::env::args_os().skip(1).collect();
     #[cfg(target_os = "linux")]
     {
       let env = Self {
@@ -289,7 +290,7 @@ impl Default for Env {
         appimage: std::env::var_os("APPIMAGE"),
         #[cfg(target_os = "linux")]
         appdir: std::env::var_os("APPDIR"),
-        args,
+        args_os,
       };
       if env.appimage.is_some() || env.appdir.is_some() {
         // validate that we're actually running on an AppImage
@@ -312,7 +313,7 @@ impl Default for Env {
     }
     #[cfg(not(target_os = "linux"))]
     {
-      Self { args }
+      Self { args_os }
     }
   }
 }

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

@@ -76,7 +76,7 @@ pub fn restart(env: &Env) {
 
   if let Ok(path) = current_binary(env) {
     Command::new(path)
-      .args(&env.args)
+      .args(&env.args_os)
       .spawn()
       .expect("application failed to start");
   }

+ 1 - 1
core/tests/restart/src/main.rs

@@ -21,7 +21,7 @@ fn main() {
   match argv.nth(1).as_deref() {
     Some("restart") => {
       let mut env = Env::default();
-      env.args.clear();
+      env.args_os.clear();
       tauri::process::restart(&env)
     }
     Some(invalid) => panic!("only argument `restart` is allowed, {invalid} is invalid"),