Medlar/crates/core/src/files.rs
2026-11-25 14:28:13 -06:00

13 lines
699 B
Rust

//! Showing a file in the desktop's file manager.
use std::path::Path;
/// Asks the file manager (`org.freedesktop.FileManager1`) to show the file selected in its folder. Blocks, so not on the
/// window's thread. An error when there is no such manager: open the folder instead.
pub fn reveal(file: &Path) -> zbus::Result<()> {
let uri = url::Url::from_file_path(file).map_err(|()| zbus::Error::Unsupported)?;
let bus = zbus::blocking::Connection::session()?;
let manager = zbus::blocking::Proxy::new(&bus, "org.freedesktop.FileManager1", "/org/freedesktop/FileManager1", "org.freedesktop.FileManager1")?;
manager.call_method("ShowItems", &(vec![uri.as_str()], ""))?;
Ok(())
}