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 serde::{Deserialize, Serialize};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
|
@ -14,6 +13,10 @@ pub struct FileItem {
|
||||||
pub size: Option<u64>,
|
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]
|
#[tauri::command]
|
||||||
pub fn list_files(path: &str) -> Result<Vec<FileItem>, String> {
|
pub fn list_files(path: &str) -> Result<Vec<FileItem>, String> {
|
||||||
let base_path = Path::new(path);
|
let base_path = Path::new(path);
|
||||||
|
|
@ -58,6 +61,10 @@ pub fn list_files(path: &str) -> Result<Vec<FileItem>, String> {
|
||||||
Ok(files)
|
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]
|
#[tauri::command]
|
||||||
pub fn upload_file(window: Window, src_path: &str, dest_path: &str) -> Result<(), String> {
|
pub fn upload_file(window: Window, src_path: &str, dest_path: &str) -> Result<(), String> {
|
||||||
let src = PathBuf::from(src_path);
|
let src = PathBuf::from(src_path);
|
||||||
|
|
@ -100,6 +107,10 @@ pub fn upload_file(window: Window, src_path: &str, dest_path: &str) -> Result<()
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a new folder at the specified path.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the folder already exists or cannot be created.
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn create_folder(path: &str, name: &str) -> Result<(), String> {
|
pub fn create_folder(path: &str, name: &str) -> Result<(), String> {
|
||||||
let full_path = Path::new(path).join(name);
|
let full_path = Path::new(path).join(name);
|
||||||
|
|
@ -112,6 +123,10 @@ pub fn create_folder(path: &str, name: &str) -> Result<(), String> {
|
||||||
Ok(())
|
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]
|
#[tauri::command]
|
||||||
pub fn delete_path(path: &str) -> Result<(), String> {
|
pub fn delete_path(path: &str) -> Result<(), String> {
|
||||||
let target = Path::new(path);
|
let target = Path::new(path);
|
||||||
|
|
@ -129,6 +144,10 @@ pub fn delete_path(path: &str) -> Result<(), String> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the user's home directory path.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the home directory cannot be determined.
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn get_home_dir() -> Result<String, String> {
|
pub fn get_home_dir() -> Result<String, String> {
|
||||||
dirs::home_dir()
|
dirs::home_dir()
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{Child, Command, Stdio};
|
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]
|
#[tauri::command]
|
||||||
pub fn start_sync(window: Window, config: Option<SyncConfig>) -> Result<SyncStatus, String> {
|
pub fn start_sync(window: Window, config: Option<SyncConfig>) -> Result<SyncStatus, String> {
|
||||||
let config = config.unwrap_or_default();
|
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]
|
#[tauri::command]
|
||||||
pub fn stop_sync() -> Result<SyncStatus, String> {
|
pub fn stop_sync() -> Result<SyncStatus, String> {
|
||||||
let mut process_guard = RCLONE_PROCESS
|
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]
|
#[tauri::command]
|
||||||
pub fn configure_remote(
|
pub fn configure_remote(
|
||||||
remote_name: &str,
|
remote_name: &str,
|
||||||
|
|
@ -225,6 +230,8 @@ pub fn configure_remote(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if rclone is not installed or the version check fails.
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn check_rclone_installed() -> Result<String, String> {
|
pub fn check_rclone_installed() -> Result<String, String> {
|
||||||
let output = Command::new("rclone")
|
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]
|
#[tauri::command]
|
||||||
pub fn list_remotes() -> Result<Vec<String>, String> {
|
pub fn list_remotes() -> Result<Vec<String>, String> {
|
||||||
let output = Command::new("rclone")
|
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]
|
#[tauri::command]
|
||||||
pub fn set_sync_folder(path: &str) -> Result<(), String> {
|
pub fn set_sync_folder(path: &str) -> Result<(), String> {
|
||||||
let path = PathBuf::from(path);
|
let path = PathBuf::from(path);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::sync::Arc;
|
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<()> {
|
pub async fn start(&self) -> Result<()> {
|
||||||
match self.running_mode {
|
match self.running_mode {
|
||||||
RunningMode::Desktop => {
|
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<()> {
|
pub async fn update_status(&self, status: &str) -> Result<()> {
|
||||||
let active = self.tray_active.read().await;
|
let active = self.tray_active.read().await;
|
||||||
let is_active = *active;
|
let is_active = *active;
|
||||||
|
|
@ -129,6 +132,8 @@ impl TrayManager {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if setting the tooltip fails.
|
||||||
pub async fn set_tooltip(&self, tooltip: &str) -> Result<()> {
|
pub async fn set_tooltip(&self, tooltip: &str) -> Result<()> {
|
||||||
let active = self.tray_active.read().await;
|
let active = self.tray_active.read().await;
|
||||||
let is_active = *active;
|
let is_active = *active;
|
||||||
|
|
@ -140,6 +145,8 @@ impl TrayManager {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the notification fails to display.
|
||||||
pub async fn show_notification(&self, title: &str, body: &str) -> Result<()> {
|
pub async fn show_notification(&self, title: &str, body: &str) -> Result<()> {
|
||||||
let active = self.tray_active.read().await;
|
let active = self.tray_active.read().await;
|
||||||
let is_active = *active;
|
let is_active = *active;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue