Skip to main content

tauri_plugin_auditaur/
lib.rs

1pub mod commands;
2pub mod desktop;
3pub mod error;
4pub mod state;
5pub mod tracing;
6
7pub use auditaur_core::AuditaurConfig;
8use tauri::{
9    plugin::{Builder as TauriPluginBuilder, TauriPlugin},
10    Manager, Runtime,
11};
12pub use tracing::tracing_layer;
13
14#[derive(Debug, Clone, Default)]
15pub struct Builder {
16    config: AuditaurConfig,
17}
18
19impl Builder {
20    pub fn new() -> Self {
21        Self::default()
22    }
23
24    pub fn service_name(mut self, service_name: impl Into<String>) -> Self {
25        self.config.service_name = Some(service_name.into());
26        self
27    }
28
29    pub fn session_name(mut self, session_name: impl Into<String>) -> Self {
30        self.config.session_name = Some(session_name.into());
31        self
32    }
33
34    pub fn redact_defaults(mut self, redact_defaults: bool) -> Self {
35        self.config.redact_defaults = redact_defaults;
36        self
37    }
38
39    pub fn max_session_bytes(mut self, max_session_bytes: u64) -> Self {
40        self.config.max_session_bytes = max_session_bytes;
41        self
42    }
43
44    pub fn allow_release_builds(mut self, allow_release_builds: bool) -> Self {
45        self.config.allow_release_builds = allow_release_builds;
46        self
47    }
48
49    pub fn build<R: Runtime>(self) -> TauriPlugin<R> {
50        let config = self.config;
51        TauriPluginBuilder::new("auditaur")
52            .invoke_handler(tauri::generate_handler![commands::export_otel_batch])
53            .setup(move |app, _api| {
54                let app_identifier = Some(app.config().identifier.clone());
55                let state = state::AuditaurState::initialize(
56                    config.clone(),
57                    std::process::id(),
58                    app_identifier,
59                )?;
60                app.manage(state);
61                Ok(())
62            })
63            .build()
64    }
65}