// Tauri Commands Module // This module contains all the commands exposed to the frontend use serde::{Deserialize, Serialize}; /// Common result type for commands pub type CommandResult = Result; /// Example payload structure #[derive(Debug, Serialize, Deserialize)] pub struct ExamplePayload { pub data: String, pub count: i32, } // Basic example command #[tauri::command] pub fn greet(name: &str) -> CommandResult { Ok(format!("Hello, {}! From Rust backend!", name)) } // Example with structured payload #[tauri::command] pub fn process_data(payload: ExamplePayload) -> CommandResult { Ok(format!("Processed: {} (count: {})", payload.data, payload.count)) } // Async command example #[tauri::command] pub async fn async_operation(input: String) -> CommandResult { // Simulate async work tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; Ok(format!("Async result from: {}", input)) } // Error handling example #[tauri::command] pub fn command_with_error(should_fail: bool) -> CommandResult { if should_fail { Err("This command failed as requested".to_string()) } else { Ok("Command succeeded!".to_string()) } } // Complex command with multiple parameters #[tauri::command] pub fn complex_command( text: String, number: i32, flag: bool, ) -> CommandResult { Ok(format!( "Text: {}, Number: {}, Flag: {}", text, number, flag )) } // Export all commands #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { // This function is called on mobile platforms }