Skip to content

Commit

Permalink
refactor!: changed Env.args to Env.args_os and use OsString ins…
Browse files Browse the repository at this point in the history
…tead of `String` (#7876)

ref: #7756
  • Loading branch information
amrbashir committed Sep 21, 2023
1 parent 092a561 commit deea943
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changes/tauri-env-args.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': 'major:breaking'
---

Changed `Env.args` to `Env.args_os` and now uses `OsString` instead of `String`
9 changes: 5 additions & 4 deletions core/tauri-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#![allow(clippy::deprecated_semver)]

use std::{
ffi::OsString,
fmt::Display,
path::{Path, PathBuf},
};
Expand Down Expand Up @@ -275,21 +276,21 @@ 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 {
#[cfg(target_os = "linux")]
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
Expand All @@ -312,7 +313,7 @@ impl Default for Env {
}
#[cfg(not(target_os = "linux"))]
{
Self { args }
Self { args_os }
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion core/tests/restart/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit deea943

Please sign in to comment.