From 5135a43e62d0b9e472985bf2304aa1dd255afb67 Mon Sep 17 00:00:00 2001 From: William Venner Date: Tue, 12 Mar 2024 17:19:23 +0000 Subject: [PATCH] Fix #217 --- src-tauri/Cargo.lock | 10 ++++++++++ src-tauri/Cargo.toml | 3 +++ src-tauri/src/util/path.rs | 30 ++++++++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 917e001..d8378e0 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1291,6 +1291,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" +[[package]] +name = "fork" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60e74d3423998a57e9d906e49252fb79eb4a04d5cdfe188fb1b7ff9fc076a8ed" +dependencies = [ + "libc", +] + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -1736,6 +1745,7 @@ dependencies = [ "dirs-next", "dunce", "erased-serde", + "fork", "fuzzy-matcher", "image 0.23.14", "indexmap 1.9.3", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 4c5687a..b449808 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -58,6 +58,9 @@ ureq = { version = "2.9.4", features = ["native-tls"] } regex = "1" steamworks = { version = "0.10", features = ["serde"] } +[target.'cfg(target_os = "linux")'.dependencies] +fork = "0.1" + [features] # this feature is used for production builds or when `devPath` points to the filesystem # DO NOT REMOVE!! diff --git a/src-tauri/src/util/path.rs b/src-tauri/src/util/path.rs index 62e933b..422e472 100644 --- a/src-tauri/src/util/path.rs +++ b/src-tauri/src/util/path.rs @@ -154,8 +154,34 @@ pub fn open_file_location>(path: P) { #[cfg(target_os = "macos")] return std::process::Command::new("open").arg("-R").arg(path.to_string()).spawn(); - #[cfg(target_os = "linux")] - return std::process::Command::new("xdg-open").arg("--select").arg(path.to_string()).spawn(); + #[cfg(target_os = "linux")] { + return if path.contains(",") { + // see https://gitlab.freedesktop.org/dbus/dbus/-/issues/76 + let new_path = match std::fs::metadata(&path).unwrap().is_dir() { + true => path, + false => { + let mut path2 = PathBuf::from(path); + path2.pop(); + path2.into_os_string().into_string().unwrap() + } + }; + return std::process::Command::new("xdg-open").arg(&new_path).spawn(); + } else { + if let Ok(fork::Fork::Child) = fork::daemon(false, false) { + return std::process::Command::new("dbus-send") + .args([ + "--session", + "--dest=org.freedesktop.FileManager1", + "--type=method_call", + "/org/freedesktop/FileManager1", + "org.freedesktop.FileManager1.ShowItems", + format!("array:string:\"file://{path}\"").as_str(), + "string:\"\"", + ]) + .spawn(); + } + }; + } #[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))] Err(std::io::Error::new(std::io::ErrorKind::Other, "Unsupported OS"))