mod builder;
mod client;
mod commands;
mod config;
mod dispatcher;
mod session;
mod sys;
use std::sync::Arc;
use std::time::Duration;
pub use builder::{Builder, PanicHook};
use client::TelemetryClient;
use serde_json::Value;
use tauri::{App, AppHandle, Manager, Runtime, Window};
pub fn init<R: Runtime>(app_key: &str) -> tauri::plugin::TauriPlugin<R> {
Builder::new(app_key).build()
}
#[derive(Default, Debug, Clone)]
pub struct InitOptions {
pub host: Option<String>,
pub flush_interval: Option<Duration>,
pub api_path: Option<String>,
pub app_key_header: Option<String>,
pub sdk_name: Option<String>,
}
pub trait EventTracker {
fn track_event(&self, name: &str, props: Option<Value>) -> Result<(), String>;
fn flush_events_blocking(&self);
}
macro_rules! impl_event_tracker {
($($t:ty),*) => {
$(
impl EventTracker for $t {
fn track_event(&self, name: &str, props: Option<Value>) -> Result<(), String> {
let client = self.state::<Arc<TelemetryClient>>();
client.track_event(name, props)
}
fn flush_events_blocking(&self) {
let client = self.state::<Arc<TelemetryClient>>();
client.flush_blocking()
}
}
)*
};
}
impl_event_tracker!(App, AppHandle, Window);