From bc875b511f7a9be11b8cb49d8be4f33e2998f015 Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Wed, 24 Dec 2025 09:29:25 -0300 Subject: [PATCH] Update drive, sync, and tray modules --- src/desktop/drive.rs | 21 ++++++++++++++++++++- src/desktop/sync.rs | 13 ++++++++++++- src/desktop/tray.rs | 9 ++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/desktop/drive.rs b/src/desktop/drive.rs index 854b3d8..315de37 100644 --- a/src/desktop/drive.rs +++ b/src/desktop/drive.rs @@ -1,4 +1,3 @@ - use serde::{Deserialize, Serialize}; use std::fs; use std::fs::File; @@ -14,6 +13,10 @@ pub struct FileItem { pub size: Option, } +/// List files in a directory. +/// +/// # Errors +/// Returns an error if the path does not exist or cannot be read. #[tauri::command] pub fn list_files(path: &str) -> Result, String> { let base_path = Path::new(path); @@ -58,6 +61,10 @@ pub fn list_files(path: &str) -> Result, String> { Ok(files) } +/// Upload a file to the specified destination. +/// +/// # Errors +/// Returns an error if the source file is invalid or the copy operation fails. #[tauri::command] pub fn upload_file(window: Window, src_path: &str, dest_path: &str) -> Result<(), String> { let src = PathBuf::from(src_path); @@ -100,6 +107,10 @@ pub fn upload_file(window: Window, src_path: &str, dest_path: &str) -> Result<() Ok(()) } +/// Create a new folder at the specified path. +/// +/// # Errors +/// Returns an error if the folder already exists or cannot be created. #[tauri::command] pub fn create_folder(path: &str, name: &str) -> Result<(), String> { let full_path = Path::new(path).join(name); @@ -112,6 +123,10 @@ pub fn create_folder(path: &str, name: &str) -> Result<(), String> { Ok(()) } +/// Delete a file or folder at the specified path. +/// +/// # Errors +/// Returns an error if the path does not exist or the item cannot be deleted. #[tauri::command] pub fn delete_path(path: &str) -> Result<(), String> { let target = Path::new(path); @@ -129,6 +144,10 @@ pub fn delete_path(path: &str) -> Result<(), String> { Ok(()) } +/// Get the user's home directory path. +/// +/// # Errors +/// Returns an error if the home directory cannot be determined. #[tauri::command] pub fn get_home_dir() -> Result { dirs::home_dir() diff --git a/src/desktop/sync.rs b/src/desktop/sync.rs index 9663470..7826fbd 100644 --- a/src/desktop/sync.rs +++ b/src/desktop/sync.rs @@ -1,4 +1,3 @@ - use serde::{Deserialize, Serialize}; use std::path::PathBuf; use std::process::{Child, Command, Stdio}; @@ -79,6 +78,8 @@ pub fn get_sync_status() -> SyncStatus { } } +/// # Errors +/// Returns an error if sync is already running, directory creation fails, or rclone is not found. #[tauri::command] pub fn start_sync(window: Window, config: Option) -> Result { let config = config.unwrap_or_default(); @@ -159,6 +160,8 @@ pub fn start_sync(window: Window, config: Option) -> Result Result { let mut process_guard = RCLONE_PROCESS @@ -185,6 +188,8 @@ pub fn stop_sync() -> Result { }) } +/// # Errors +/// Returns an error if rclone configuration fails. #[tauri::command] pub fn configure_remote( remote_name: &str, @@ -225,6 +230,8 @@ pub fn configure_remote( Ok(()) } +/// # Errors +/// Returns an error if rclone is not installed or the version check fails. #[tauri::command] pub fn check_rclone_installed() -> Result { let output = Command::new("rclone") @@ -247,6 +254,8 @@ pub fn check_rclone_installed() -> Result { } } +/// # Errors +/// Returns an error if listing rclone remotes fails. #[tauri::command] pub fn list_remotes() -> Result, String> { let output = Command::new("rclone") @@ -275,6 +284,8 @@ pub fn get_sync_folder() -> String { ) } +/// # Errors +/// Returns an error if the directory cannot be created or the path is not a directory. #[tauri::command] pub fn set_sync_folder(path: &str) -> Result<(), String> { let path = PathBuf::from(path); diff --git a/src/desktop/tray.rs b/src/desktop/tray.rs index e903e14..569df76 100644 --- a/src/desktop/tray.rs +++ b/src/desktop/tray.rs @@ -1,4 +1,3 @@ - use anyhow::Result; use serde::Serialize; use std::sync::Arc; @@ -45,6 +44,8 @@ impl TrayManager { } } + /// # Errors + /// Returns an error if the tray system fails to initialize. pub async fn start(&self) -> Result<()> { match self.running_mode { RunningMode::Desktop => { @@ -118,6 +119,8 @@ impl TrayManager { } } + /// # Errors + /// Returns an error if the status update fails. pub async fn update_status(&self, status: &str) -> Result<()> { let active = self.tray_active.read().await; let is_active = *active; @@ -129,6 +132,8 @@ impl TrayManager { Ok(()) } + /// # Errors + /// Returns an error if setting the tooltip fails. pub async fn set_tooltip(&self, tooltip: &str) -> Result<()> { let active = self.tray_active.read().await; let is_active = *active; @@ -140,6 +145,8 @@ impl TrayManager { Ok(()) } + /// # Errors + /// Returns an error if the notification fails to display. pub async fn show_notification(&self, title: &str, body: &str) -> Result<()> { let active = self.tray_active.read().await; let is_active = *active;