mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-10-10 22:38:44 +02:00
fix(single-instance): forward non-Unicode arguments and cwd (#3644)
* Update windows.rs * Create single-instance-non-unicode-args.md * fix on linux and windows too --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
1 parent
677258138b
commit
323fe80df1
5 files changed
+24
-11
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"single-instance": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
A second instance no longer panics when a command-line argument is not valid Unicode: such an argument is forwarded with its invalid parts replaced by U+FFFD. A working directory that is not valid Unicode is now forwarded the same way instead of as an empty string.
|
||||||
@@ -39,8 +39,9 @@ pub(crate) type SingleInstanceCallback<R> =
|
|||||||
/// [`Builder::build`]. Use [`Builder`] directly if you need to set a custom [`Builder::dbus_id`].
|
/// [`Builder::build`]. Use [`Builder`] directly if you need to set a custom [`Builder::dbus_id`].
|
||||||
///
|
///
|
||||||
/// `f` is called with the app handle, the second instance's command line arguments
|
/// `f` is called with the app handle, the second instance's command line arguments
|
||||||
/// (as collected by [`std::env::args`], so the first element is the executable path) and its
|
/// (as collected by [`std::env::args_os`], so the first element is the executable path) and its
|
||||||
/// current working directory. If the `deep-link` feature is enabled, the arguments are first
|
/// current working directory. Arguments and the working directory that are not valid Unicode
|
||||||
|
/// have their invalid parts replaced by U+FFFD. If the `deep-link` feature is enabled, the arguments are first
|
||||||
/// forwarded to [`tauri-plugin-deep-link`](https://crates.io/crates/tauri-plugin-deep-link)
|
/// forwarded to [`tauri-plugin-deep-link`](https://crates.io/crates/tauri-plugin-deep-link)
|
||||||
/// before `f` runs.
|
/// before `f` runs.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -74,11 +74,13 @@ pub fn init<R: Runtime>(
|
|||||||
Some("org.SingleInstance.DBus"),
|
Some("org.SingleInstance.DBus"),
|
||||||
"ExecuteCallback",
|
"ExecuteCallback",
|
||||||
&(
|
&(
|
||||||
std::env::args().collect::<Vec<String>>(),
|
std::env::args_os()
|
||||||
|
.map(|arg| arg.to_string_lossy().into_owned())
|
||||||
|
.collect::<Vec<String>>(),
|
||||||
std::env::current_dir()
|
std::env::current_dir()
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.to_str()
|
.to_string_lossy()
|
||||||
.unwrap_or_default(),
|
.as_ref(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,12 +80,14 @@ fn notify_singleton(socket: &PathBuf) -> Result<(), Error> {
|
|||||||
let mut bf = BufWriter::new(&stream);
|
let mut bf = BufWriter::new(&stream);
|
||||||
let cwd = std::env::current_dir()
|
let cwd = std::env::current_dir()
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.to_str()
|
.to_string_lossy()
|
||||||
.unwrap_or_default()
|
.into_owned();
|
||||||
.to_string();
|
|
||||||
bf.write_all(cwd.as_bytes())?;
|
bf.write_all(cwd.as_bytes())?;
|
||||||
bf.write_all(b"\0\0")?;
|
bf.write_all(b"\0\0")?;
|
||||||
let args_joined = std::env::args().collect::<Vec<String>>().join("\0");
|
let args_joined = std::env::args_os()
|
||||||
|
.map(|arg| arg.to_string_lossy().into_owned())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join("\0");
|
||||||
bf.write_all(args_joined.as_bytes())?;
|
bf.write_all(args_joined.as_bytes())?;
|
||||||
bf.flush()?;
|
bf.flush()?;
|
||||||
drop(bf);
|
drop(bf);
|
||||||
|
|||||||
@@ -86,9 +86,12 @@ pub fn init<R: Runtime>(callback: Box<SingleInstanceCallback<R>>) -> TauriPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
let cwd = std::env::current_dir().unwrap_or_default();
|
let cwd = std::env::current_dir().unwrap_or_default();
|
||||||
let cwd = cwd.to_str().unwrap_or_default();
|
let cwd = cwd.to_string_lossy();
|
||||||
|
|
||||||
let args = std::env::args().collect::<Vec<String>>().join("|");
|
let args = std::env::args_os()
|
||||||
|
.map(|arg| arg.to_string_lossy().into_owned())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join("|");
|
||||||
|
|
||||||
let data = format!("{cwd}|{args}\0",);
|
let data = format!("{cwd}|{args}\0",);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user