game_manager_lib\commands/
system.rs1use crate::errors::AppError;
4use tauri_plugin_opener::OpenerExt;
5
6#[tauri::command]
8pub async fn open_folder(app: tauri::AppHandle, path: String) -> Result<(), AppError> {
9 let path_obj = std::path::Path::new(&path);
11
12 if !path_obj.exists() {
14 std::fs::create_dir_all(path_obj)
15 .map_err(|e| AppError::IoError(format!("Erro ao criar pasta: {}", e)))?;
16 }
17
18 if !path_obj.is_dir() {
19 return Err(AppError::IoError(format!(
20 "O caminho não é uma pasta: {}",
21 path
22 )));
23 }
24
25 app.opener()
27 .open_path(&path, None::<&str>)
28 .map_err(|e| AppError::IoError(format!("Erro ao abrir pasta: {}", e)))?;
29
30 Ok(())
31}
32
33#[tauri::command]
35pub async fn open_file(app: tauri::AppHandle, path: String) -> Result<(), AppError> {
36 let path_obj = std::path::Path::new(&path);
38
39 if !path_obj.exists() {
40 return Err(AppError::NotFound(format!(
41 "Arquivo não encontrado: {}",
42 path
43 )));
44 }
45
46 if !path_obj.is_file() {
47 return Err(AppError::IoError(format!(
48 "O caminho não é um arquivo: {}",
49 path
50 )));
51 }
52
53 app.opener()
55 .open_path(&path, None::<&str>)
56 .map_err(|e| AppError::IoError(format!("Erro ao abrir arquivo: {}", e)))?;
57
58 Ok(())
59}