Skip to main content

init

Function init 

Source
pub fn init<R: Runtime>(router: Router) -> TauriPlugin<R>
Expand description

Create a Tauri 2.x plugin that exposes AllFrame handlers via IPC.

The Tauri AppHandle<R> is automatically injected as state during plugin setup, so handlers registered with register_with_state::<AppHandle<R>, …> (or any *_with_state* variant) can access it directly.

§Example

use allframe_core::router::{Router, State};
use std::sync::Arc;
use tauri::AppHandle;

fn main() {
    let mut router = Router::new();
    router.register("greet", || async { "Hello!".to_string() });

    // AppHandle<tauri::Wry> is auto-injected — handlers can request it:
    router.register_with_state_only::<AppHandle<tauri::Wry>, _, _>(
        "send_notification",
        |app: State<Arc<AppHandle<tauri::Wry>>>| async move {
            // app.emit("event", &payload).unwrap();
            "sent".to_string()
        },
    );

    tauri::Builder::default()
        .plugin(allframe_tauri::init(router))
        .run(tauri::generate_context!())
        .unwrap();
}