feat: implement native OS file management and trash utilities

This commit is contained in:
NimBold
2026-06-16 15:45:22 +03:30
parent e41e761b33
commit 2727d07d62
7 changed files with 185 additions and 13 deletions
+83
View File
@@ -0,0 +1,83 @@
use std::process::Command;
use std::path::Path;
#[tauri::command]
pub async fn reveal_in_file_manager(path: String) -> Result<(), String> {
#[cfg(target_os = "macos")]
{
Command::new("open")
.arg("-R")
.arg(&path)
.spawn()
.map_err(|e| format!("Failed to reveal file: {}", e))?;
}
#[cfg(target_os = "windows")]
{
Command::new("explorer.exe")
.arg(format!("/select,\"{}\"", path))
.spawn()
.map_err(|e| format!("Failed to reveal file: {}", e))?;
}
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
{
let parent = Path::new(&path).parent().unwrap_or(Path::new(""));
Command::new("xdg-open")
.arg(parent)
.spawn()
.map_err(|e| format!("Failed to reveal file: {}", e))?;
}
Ok(())
}
#[tauri::command]
pub async fn open_downloaded_file(path: String) -> Result<(), String> {
#[cfg(target_os = "macos")]
{
Command::new("open")
.arg(&path)
.spawn()
.map_err(|e| format!("Failed to open file: {}", e))?;
}
#[cfg(target_os = "windows")]
{
Command::new("cmd")
.args(["/c", "start", "", &path])
.spawn()
.map_err(|e| format!("Failed to open file: {}", e))?;
}
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
{
Command::new("xdg-open")
.arg(&path)
.spawn()
.map_err(|e| format!("Failed to open file: {}", e))?;
}
Ok(())
}
#[tauri::command]
pub async fn trash_download_assets(path: String, partial_paths: Vec<String>) -> Result<(), String> {
let p = Path::new(&path);
if p.exists() {
if let Err(e) = trash::delete(p) {
return Err(format!("Failed to trash primary file: {}", e));
}
}
for partial in partial_paths {
let p_partial = Path::new(&partial);
if p_partial.exists() {
if let Err(e) = trash::delete(p_partial) {
return Err(format!("Failed to trash partial file: {}", e));
}
}
}
Ok(())
}
+2
View File
@@ -423,6 +423,7 @@ pub mod download;
mod ipc;
mod parity;
pub mod error;
pub mod commands;
pub use error::AppError;
// Retained only for compatibility with the optional aria2 diagnostic monitor.
@@ -1704,6 +1705,7 @@ pub fn run() {
set_keychain_password, get_keychain_password, delete_keychain_password,
check_file_exists, delete_file, toggle_tray_icon, set_extension_pairing_token,
set_extension_frontend_ready, set_concurrent_limit, set_global_speed_limit, remove_download,
commands::reveal_in_file_manager, commands::open_downloaded_file, commands::trash_download_assets,
parity::get_system_proxy, parity::get_file_category, parity::check_for_updates, parity::is_supported_media, parity::get_supported_media_domains,
parity::create_category_directories
])