From deea9436261f651188e0bc86104779bf30029c32 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Thu, 21 Sep 2023 15:56:03 +0300 Subject: [PATCH] refactor!: changed `Env.args` to `Env.args_os` and use `OsString` instead of `String` (#7876) ref: https://github.com/tauri-apps/tauri/issues/7756 --- .changes/tauri-env-args.md | 5 +++++ core/tauri-utils/src/lib.rs | 9 +++++---- core/tauri/src/process.rs | 2 +- core/tests/restart/src/main.rs | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 .changes/tauri-env-args.md diff --git a/.changes/tauri-env-args.md b/.changes/tauri-env-args.md new file mode 100644 index 000000000000..8c02c9b2f8d7 --- /dev/null +++ b/.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` diff --git a/core/tauri-utils/src/lib.rs b/core/tauri-utils/src/lib.rs index a9fbf6622fc9..11794fef8789 100644 --- a/core/tauri-utils/src/lib.rs +++ b/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, /// The command line arguments of the current process. - pub args: Vec, + pub args_os: Vec, } #[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 } } } } diff --git a/core/tauri/src/process.rs b/core/tauri/src/process.rs index 7eef25939acf..de205a56f3be 100644 --- a/core/tauri/src/process.rs +++ b/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"); } diff --git a/core/tests/restart/src/main.rs b/core/tests/restart/src/main.rs index 6984ab20c5d3..a37a66643d39 100644 --- a/core/tests/restart/src/main.rs +++ b/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"),