v2
Installation
[!WARNING] Tauri Specta v2 is still in beta, until Tauri v2 lands as stable.
However, it's safe to use as long as you lock your versions.
Adding Specta to custom types
Annotate your Tauri commands with Specta
Export your bindings
Usage on frontend
Events
You must reconfigure your builder to support events:
Now you can add your first event. You can add as many of these as your want.
and make sure you register the event with Tauri Specta by adding it to the collect_events
macro like the following:
Finally, you can setup a listener or emit a message from Rust like the following:
Most methods take a handle
which can be any of the following types:
The Event
trait defines all methods that can be used to emit or listen so refer to it.
and it can be used in TS like the following:
Extra Types
Sometimes you might want to export a type to Typescript but it doesn't actually show up in any of our commands.
You can do that like the following:
register
only supports named types as otherwise you would run into the following problem:
Any type implemented using the Type
derive macro will meet this requirement.
Constants
It may be useful to export a constant from your Rust into your Typescript. You can do this like the following:
This value must implement serde::Serialize
.
File header
It's very common that your are using a linting or formatting tool on your codebase and it's likely that the output of Tauri Specta will not match your style. You can configure the header of the file like the following to solve this:
Last updated on