Rust Backend
The backend is built with Tauri and Rust. It handles system-level operations, file system access, and heavy computations.
Structure
The Rust code is located in src-tauri/src.
main.rs: Initializes the Tauri application, sets up plugins, and runs the app.lib.rs: Defines therunfunction and registers commands.logger.rs: Implements the backend logging logic usinglog4rs.
Commands
Tauri commands are Rust functions annotated with #[tauri::command]. They can be called from the frontend.
Example Command
rust
#[tauri::command]
pub fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}To add a new command:
- Define the function in
lib.rs(or a separate module). - Register it in the
tauri::Builderhandler inlib.rs. - Add a corresponding method in
TauriService.tson the frontend.
Capabilities
Tauri v2 uses a capability-based security model. Permissions are defined in src-tauri/capabilities/default.json.
If you add a plugin (e.g., fs, http), make sure to enable the required permissions in the capabilities file.