| Crates.io | tauri-helper |
| lib.rs | tauri-helper |
| version | 0.1.4 |
| created_at | 2025-03-19 15:15:40.43632+00 |
| updated_at | 2025-04-18 15:04:49.016572+00 |
| description | A collection of tools and utilities designed to simplify the development of Tauri applications. |
| homepage | https://github.com/RiadYan/tauri-helper |
| repository | https://github.com/RiadYan/tauri-helper |
| max_upload_size | |
| id | 1598136 |
| size | 26,046 |
tauri_helpertauri_helper is a collection of tools and utilities designed to simplify the development of Tauri applications. It provides macros, utilities, and automation to streamline common tasks such as command collection, error handling, and workspace management.
This workspace includes the following crates:
tauri_helper_core: Core utilities for workspace management and command collection.tauri_helper_macros: Procedural macros for automating Tauri command registration and error handling.#[auto_collect_command]: Automatically collect Tauri commands annotated with this attribute.specta_collect_commands!: Generate a tauri_specta::collect_commands! invocation for all collected commands.tauri_collect_commands!: Generate a tauri::generate_handler! invocation for all collected commands.array_collect_commands!: Generate an array of collected command names, optionally printing them.WithLogging: Automatically implement From for enum variants and optionally log errors using tracing (requires the tracing feature), this is extremely unstable.Add tauri_helper to your Cargo.toml:
[dependencies]
tauri_helper = "0.1.1"
If you want to use the WithLogging macro with tracing, enable the tracing feature:
[dependencies]
tauri_helper = { version = "0.1.1", features = ["tracing"] }
Then add it to the [build-dependencies] :
[build-dependencies]
tauri_helper = "0.1.1"
Before using any command collection, you have to add this to the build.rs file.
fn main() {
tauri_helper::generate_command_file(tauri_helper::TauriHelperOptions::default());
tauri_build::build();
}
Annotate your Tauri command functions with #[auto_collect_command] to automatically collect them:
#[tauri::command]
#[auto_collect_command]
fn greet(name: String) -> String {
format!("Hello, {}!", name)
}
Generate a tauri::generate_handler! invocation:
tauri_collect_commands!();
Generate a tauri_specta::collect_commands! invocation:
specta_collect_commands!();
If you do not want to have to annotate every command with #[auto_collect_command], you can do this in the build.rs.
fn main() {
tauri_helper::generate_command_file(tauri_helper::TauriHelperOptions::new(true));
tauri_build::build();
}
This will tell the build script to get every tauri_command available in every member of the workspace.
This is not recommended as it can lead to adding functions that are not meant to be exported.
If your workspace contains multiple crates, you must export all functions in the root file (lib.rs) of each crate.
In my_commands.rs:
#[tauri::command]
#[auto_collect_command]
fn greet(name: String) -> String {
format!("Hello, {}!", name)
}
In lib.rs:
pub mod my_commands;
pub use my_commands::*;
Note: This is required because the feature that enables full module path retrieval is still only available in the nightly version of Rust.
Here’s a complete example of using tauri_helper in a Tauri application:
#[tauri::command]
#[auto_collect_command]
fn greet(name: String) -> String {
format!("Hello, {}!", name)
}
#[tauri::command]
#[auto_collect_command]
fn calculate_sum(a: i32, b: i32) -> i32 {
a + b
}
fn main() {
let builder: tauri_specta::Builder = tauri_specta::Builder::<tauri::Wry>::new()
.commands(specta_collect_commands!());
#[cfg(debug_assertions)]
builder
.export(
Typescript::default().bigint(specta_typescript::BigIntExportBehavior::Number),
"../src/bindings.ts",
)
.expect("should work");
tauri::Builder::default()
.invoke_handler(tauri_collect_commands!())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
tracing: Enables tracing support in the WithLogging macro. This feature is optional and must be explicitly enabled.WithLogging Stability: The WithLogging macro is experimental and may undergo breaking changes. It is not recommended for production use.#[auto_collect_command] to be included in the generated handlers by default.#[command] that comes from tauri.Contributions are welcome! Please open an issue or submit a pull request if you have any improvements or bug fixes.
This project is licensed under the MIT License.