mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-08-11 17:32:11 +00:00
refactor file manager path resolution and target opening logic
This commit is contained in:
parent
867e5dfd77
commit
ff93f98625
@ -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!(
|
||||
"The path does not exist and its parent folder could not be found: {}",
|
||||
requested_path.to_string_lossy(),
|
||||
);
|
||||
error!(Source = "Tauri"; "{issue}");
|
||||
return Json(OpenPathResponse {
|
||||
success: false,
|
||||
issue,
|
||||
});
|
||||
return Err(issue);
|
||||
};
|
||||
|
||||
#[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 {
|
||||
Ok(()) => {
|
||||
info!("Opened file manager for path: {:?}", target.path);
|
||||
Json(OpenPathResponse {
|
||||
success: true,
|
||||
issue: String::new(),
|
||||
})
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Err(issue) => {
|
||||
error!(Source = "Tauri"; "{issue}");
|
||||
Json(OpenPathResponse {
|
||||
success: false,
|
||||
issue,
|
||||
})
|
||||
}
|
||||
Err(issue) => Err(issue),
|
||||
};
|
||||
}
|
||||
|
||||
@ -366,19 +379,12 @@ pub async fn open_path_in_file_manager(
|
||||
match command.spawn() {
|
||||
Ok(_) => {
|
||||
info!("Opened file manager for path: {:?}", target.path);
|
||||
Json(OpenPathResponse {
|
||||
success: true,
|
||||
issue: String::new(),
|
||||
})
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Err(error) => {
|
||||
let issue = format!("Failed to open the file manager: {error}");
|
||||
error!(Source = "Tauri"; "{issue}");
|
||||
Json(OpenPathResponse {
|
||||
success: false,
|
||||
issue,
|
||||
})
|
||||
Err(issue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user