> Tauri State & Events
Manage shared state and bidirectional events between Rust and frontend in Tauri apps.
fetch
$
curl "https://skillshub.wtf/skillshub-team/catalog-batch5/tauri-state-events?format=md"SKILL.md•Tauri State & Events
Tauri State & Events
Shared State
use std::sync::Mutex;
use tauri::State;
struct AppState { counter: Mutex<i32> }
#[tauri::command]
fn increment(state: State<AppState>) -> i32 {
let mut c = state.counter.lock().unwrap();
*c += 1; *c
}
// Register: .manage(AppState { counter: Mutex::new(0) })
Events (Rust → Frontend)
use tauri::{AppHandle, Emitter};
#[tauri::command]
async fn long_task(app: AppHandle) {
for i in 0..100 {
app.emit("progress", i).unwrap();
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
}
}
import { listen } from "@tauri-apps/api/event";
await listen<number>("progress", (e) => console.log(e.payload));
Error Handling
#[tauri::command]
fn risky_op() -> Result<String, String> {
Err("Something failed".into()) // Reaches frontend as error
}
> related_skills --same-repo
> Nix Dev Shells with direnv
Auto-activate reproducible dev environments with Nix flakes and direnv.
> Dagger with GitHub Actions
Run Dagger CI/CD pipelines in GitHub Actions for portable, testable builds.
> Bun + Hono API
Build fast APIs with Bun runtime and Hono framework.
> Deno Fresh Framework
Build full-stack web apps with Fresh on Deno. Islands, routes, and zero runtime overhead.