pub fn clipboard_read() -> Option<String> {
arboard::Clipboard::new()
.ok()
.and_then(|mut cb| cb.get_text().ok())
}
pub fn clipboard_write(text: impl Into<String>) {
if let Ok(mut cb) = arboard::Clipboard::new() {
let _ = cb.set_text(text.into());
}
}
use std::path::PathBuf;
pub fn pick_file() -> Option<PathBuf> {
rfd::FileDialog::new().pick_file()
}
pub fn pick_files() -> Vec<PathBuf> {
rfd::FileDialog::new().pick_files().unwrap_or_default()
}
pub fn pick_folder() -> Option<PathBuf> {
rfd::FileDialog::new().pick_folder()
}
pub fn save_file(default_name: impl Into<String>) -> Option<PathBuf> {
rfd::FileDialog::new()
.set_file_name(default_name.into())
.save_file()
}
pub fn pick_file_filtered(title: &str, extensions: &[&str]) -> Option<PathBuf> {
rfd::FileDialog::new()
.set_title(title)
.add_filter("Files", extensions)
.pick_file()
}
pub fn notify(title: impl Into<String>, body: impl Into<String>) {
let _ = (title.into(), body.into());
}
pub fn open_url(url: impl Into<String>) {
let url = url.into();
#[cfg(target_os = "macos")]
{ let _ = std::process::Command::new("open").arg(&url).spawn(); }
#[cfg(target_os = "windows")]
{ let _ = std::process::Command::new("cmd").args(["/C", "start", &url]).spawn(); }
#[cfg(target_os = "linux")]
{ let _ = std::process::Command::new("xdg-open").arg(&url).spawn(); }
}
pub fn reveal_in_explorer(path: impl Into<std::path::PathBuf>) {
let path = path.into();
#[cfg(target_os = "macos")]
{ let _ = std::process::Command::new("open").arg("-R").arg(&path).spawn(); }
#[cfg(target_os = "windows")]
{ let _ = std::process::Command::new("explorer").arg(format!("/select,{}", path.display())).spawn(); }
#[cfg(target_os = "linux")]
{ let _ = std::process::Command::new("xdg-open").arg(path.parent().unwrap_or(&path)).spawn(); }
}