Update drive, sync, and tray modules
This commit is contained in:
parent
20232432c6
commit
bc875b511f
3 changed files with 40 additions and 3 deletions
|
|
@ -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<u64>,
|
||||
}
|
||||
|
||||
/// 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<Vec<FileItem>, String> {
|
||||
let base_path = Path::new(path);
|
||||
|
|
@ -58,6 +61,10 @@ pub fn list_files(path: &str) -> Result<Vec<FileItem>, 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<String, String> {
|
||||
dirs::home_dir()
|
||||
|
|
|
|||
|
|
@ -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<SyncConfig>) -> Result<SyncStatus, String> {
|
||||
let config = config.unwrap_or_default();
|
||||
|
|
@ -159,6 +160,8 @@ pub fn start_sync(window: Window, config: Option<SyncConfig>) -> Result<SyncStat
|
|||
})
|
||||
}
|
||||
|
||||
/// # Errors
|
||||
/// Returns an error if no sync process is currently running.
|
||||
#[tauri::command]
|
||||
pub fn stop_sync() -> Result<SyncStatus, String> {
|
||||
let mut process_guard = RCLONE_PROCESS
|
||||
|
|
@ -185,6 +188,8 @@ pub fn stop_sync() -> Result<SyncStatus, String> {
|
|||
})
|
||||
}
|
||||
|
||||
/// # 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<String, String> {
|
||||
let output = Command::new("rclone")
|
||||
|
|
@ -247,6 +254,8 @@ pub fn check_rclone_installed() -> Result<String, String> {
|
|||
}
|
||||
}
|
||||
|
||||
/// # Errors
|
||||
/// Returns an error if listing rclone remotes fails.
|
||||
#[tauri::command]
|
||||
pub fn list_remotes() -> Result<Vec<String>, 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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue