Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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/fix-macos-cwd-single-instance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
single-instance: patch
---

fix `cwd` in single instance on macOS, which was the cwd of the first instance, instead of the second (like it is on windows and linux)
18 changes: 10 additions & 8 deletions plugins/single-instance/src/platform_impl/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ fn socket_cleanup(socket: &PathBuf) {
fn notify_singleton(socket: &PathBuf) -> Result<(), Error> {
let stream = UnixStream::connect(socket)?;
let mut bf = BufWriter::new(&stream);
let cwd = std::env::current_dir()
.unwrap_or_default()
.to_str()
.unwrap_or_default()
.to_string();
bf.write_all(cwd.as_bytes())?;
bf.write_all(b"\0\0")?;
let args_joined = std::env::args().collect::<Vec<String>>().join("\0");
bf.write_all(args_joined.as_bytes())?;
bf.flush()?;
Expand All @@ -91,22 +98,17 @@ fn listen_for_other_instances<A: Runtime>(
) {
match UnixListener::bind(socket) {
Ok(listener) => {
let cwd = std::env::current_dir()
.unwrap_or_default()
.to_str()
.unwrap_or_default()
.to_string();

tauri::async_runtime::spawn(async move {
for stream in listener.incoming() {
match stream {
Ok(mut stream) => {
let mut s = String::new();
match stream.read_to_string(&mut s) {
Ok(_) => {
let (cwd, args) = s.split_once("\0\0").unwrap_or_default();
let args: Vec<String> =
s.split('\0').map(String::from).collect();
cb(app.app_handle(), args, cwd.clone());
args.split('\0').map(String::from).collect();
cb(app.app_handle(), args, cwd.to_string());
}
Err(e) => {
tracing::debug!("single_instance failed to be notified: {e}")
Expand Down
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tab_spaces = 4
Loading