tauri_plugin_posthog/
lib.rs1use tauri::{
2 plugin::{Builder, TauriPlugin},
3 Manager, Runtime,
4};
5
6mod client;
7mod commands;
8mod error;
9mod models;
10
11use client::PostHogClientWrapper;
12pub use error::{Error, Result};
13pub use models::{
14 default_api_host, AliasRequest, CaptureRequest, IdentifyRequest, PostHogConfig, PostHogOptions,
15};
16
17pub trait PostHogExt<R: Runtime> {
18 fn posthog(&self) -> &PostHogClientWrapper;
19}
20
21impl<R: Runtime, T: Manager<R>> PostHogExt<R> for T {
22 fn posthog(&self) -> &PostHogClientWrapper {
23 self.state::<PostHogClientWrapper>().inner()
24 }
25}
26
27pub fn init<R: Runtime>(config: PostHogConfig) -> TauriPlugin<R, ()> {
29 Builder::<R>::new("posthog")
30 .invoke_handler(tauri::generate_handler![
31 commands::capture,
32 commands::identify,
33 commands::alias,
34 commands::reset,
35 commands::get_distinct_id,
36 commands::get_config,
37 ])
38 .setup(move |app, _api| {
39 tauri::async_runtime::block_on(async {
40 let client = PostHogClientWrapper::new(config).await?;
41 app.manage(client);
42 Ok(())
43 })
44 })
45 .build()
46}