--- description: Rust backend conventions for Tauri commands and database globs: src-tauri/src/**/*.rs alwaysApply: false --- # Rust Backend Conventions ## Tauri Commands - All IPC commands live in `commands.rs`, annotated with `#[tauri::command]` - Commands that need DB access take `State<'_, DbState>` - Commands that need the app handle take `app: tauri::AppHandle` - Return `Result` — map errors with `.map_err(|e| e.to_string())` - Register every new command in `lib.rs` → `invoke_handler` ## Database (db.rs) - `Database` wraps `Mutex` for thread safety - Use `Database::in_memory()` in tests, `Database::new()` in production - Settings are key-value in the `settings` table; add defaults in `init_tables()` - FTS5 table `clipboard_fts` syncs via triggers on insert/delete ## macOS-Specific Code - Gate with `#[cfg(target_os = "macos")]` - Cursor position: use `core-graphics` crate's `CGEvent` (not Tauri's `cursor_position()` which is window-relative) - AppleScript for paste simulation: always use `.output()` not `.spawn()` to ensure execution completes