Skip to main content

tauri_plugin_picoframe_hello/
lib.rs

1//! Example "hello" plugin (Rust half). Proves the full-stack picoframe plugin
2//! contract: a Tauri v2 plugin exposing one command that returns a [`CliResult`].
3
4use picoframe_core::CliResult;
5use serde_json::json;
6use tauri::{
7    plugin::{Builder, TauriPlugin},
8    Runtime,
9};
10
11#[tauri::command]
12async fn hello_greet(name: String) -> CliResult {
13    let name = if name.trim().is_empty() { "world".to_string() } else { name };
14    CliResult::ok(json!({ "message": format!("Hello, {name}!") }))
15}
16
17/// Build the plugin. Registered as `"picoframe-hello"` (the crate name minus the
18/// `tauri-plugin-` prefix), so the frontend invokes `plugin:picoframe-hello|hello_greet`.
19pub fn init<R: Runtime>() -> TauriPlugin<R> {
20    Builder::new("picoframe-hello")
21        .invoke_handler(tauri::generate_handler![hello_greet])
22        .build()
23}