listening-to-tauri-events

Implements typed Tauri v2 event listeners in frontend code with cleanup patterns.

Updated Jun 7, 2026
One-click install
npx skills add https://github.com/dt418/better-shot-x --skill listening-to-tauri-events-dt418
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: listening-to-tauri-events
Source: https://github.com/dt418/better-shot-x/tree/main/.agents/skills/listening-to-tauri-events
Command: npx skills add https://github.com/dt418/better-shot-x --skill listening-to-tauri-events-dt418

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @tauri-apps/api.

What problem does it solve? Frontend code in a Tauri v2 desktop app needs to react to events emitted from the Rust backend, and doing this incorrectly causes type mismatches, missed webview-scoped events, and memory leaks from listeners that are never unsubscribed. ## Core Features & Use Cases - Typed Event Subscriptions: Subscribe to global and webview-specific events using listen, once, and getCurrentWebviewWindow with TypeScript generics matching Rust payload structs. - Lifecycle Cleanup Patterns: Provides unlisten patterns for React, Vue, and Svelte components, plus multi-listener cleanup and an event bus abstraction. - Rust Emit Reference: Shows the corresponding emit, emit_to, and emit_filter Rust code so frontend and backend event contracts stay aligned. - Use Case: When building a download manager UI in a Tauri app, use this Skill to wire up typed download-progress listeners that update the interface and clean themselves up when the component unmounts. ## Quick Start Show me how to listen for a typed download-progress event from my Tauri Rust backend in a React component with proper cleanup.

Frequently Asked Questions about listening-to-tauri-events

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I listen for Tauri events in the frontend?

Import listen from @tauri-apps/api/event and call it with the event name and a callback. It returns a promise resolving to an unlisten function you must call when the listener is no longer needed.

How to type Tauri event payloads in TypeScript?

Define a TypeScript interface matching your Rust struct and pass it as a generic to listen, such as listen<MyPayload>('event-name', handler). Use serde rename_all camelCase in Rust so field names align with JavaScript conventions.

Why is my Tauri global listener not receiving emit_to events?

Events sent with emit_to or emit_filter target specific webviews and are not delivered to global listeners. Use getCurrentWebviewWindow().listen() in the targeted webview to receive them.

Do Tauri event listeners need manual cleanup in React?

Yes, listeners persist until you call the returned unlisten function. In React, register the listener inside useEffect and call unlisten in the cleanup function, since SPA routers do not trigger automatic listener clearing.

When should I use once instead of listen in Tauri?

Use once for events that fire a single time, such as initialization or app-ready signals. It automatically unsubscribes after the first invocation, avoiding manual cleanup for one-shot notifications.