Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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