refactor file manager path resolution and target opening logic

This commit is contained in:
nilsk 2026-07-21 13:31:42 +02:00
parent 867e5dfd77
commit ff93f98625
No known key found for this signature in database
GPG Key ID: A5C0151B4DDB172C

View File

@ -323,16 +323,38 @@ pub async fn open_path_in_file_manager(
}); });
} }
let Some(target) = resolve_file_manager_target(&requested_path) else { match open_file_manager_target(&requested_path).await {
Ok(()) => Json(OpenPathResponse {
success: true,
issue: String::new(),
}),
Err(issue) => {
error!(Source = "Tauri"; "{issue}");
Json(OpenPathResponse {
success: false,
issue,
})
}
}
}
#[cfg(target_os = "linux")]
pub(crate) async fn open_existing_file_in_file_manager(path: PathBuf) -> Result<(), String> {
if !path.is_file() {
return Err(format!("The requested path is not an existing file: {}", path.to_string_lossy()));
}
open_file_manager_target(&path).await
}
async fn open_file_manager_target(requested_path: &Path) -> Result<(), String> {
let Some(target) = resolve_file_manager_target(requested_path) else {
let issue = format!( let issue = format!(
"The path does not exist and its parent folder could not be found: {}", "The path does not exist and its parent folder could not be found: {}",
requested_path.to_string_lossy(), requested_path.to_string_lossy(),
); );
error!(Source = "Tauri"; "{issue}"); return Err(issue);
return Json(OpenPathResponse {
success: false,
issue,
});
}; };
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
@ -340,19 +362,10 @@ pub async fn open_path_in_file_manager(
return match open_path_in_linux_file_manager(&target).await { return match open_path_in_linux_file_manager(&target).await {
Ok(()) => { Ok(()) => {
info!("Opened file manager for path: {:?}", target.path); info!("Opened file manager for path: {:?}", target.path);
Json(OpenPathResponse { Ok(())
success: true,
issue: String::new(),
})
} }
Err(issue) => { Err(issue) => Err(issue),
error!(Source = "Tauri"; "{issue}");
Json(OpenPathResponse {
success: false,
issue,
})
}
}; };
} }
@ -366,19 +379,12 @@ pub async fn open_path_in_file_manager(
match command.spawn() { match command.spawn() {
Ok(_) => { Ok(_) => {
info!("Opened file manager for path: {:?}", target.path); info!("Opened file manager for path: {:?}", target.path);
Json(OpenPathResponse { Ok(())
success: true,
issue: String::new(),
})
} }
Err(error) => { Err(error) => {
let issue = format!("Failed to open the file manager: {error}"); let issue = format!("Failed to open the file manager: {error}");
error!(Source = "Tauri"; "{issue}"); Err(issue)
Json(OpenPathResponse {
success: false,
issue,
})
} }
} }
} }