tauri_plugin_plauth/
lib.rs1use tauri::{
2 plugin::{Builder, TauriPlugin},
3 Manager, Runtime,
4};
5
6pub use models::*;
7
8#[cfg(any(target_os = "windows", target_os = "linux"))]
9mod desktop;
10#[cfg(target_os = "macos")]
11mod macos;
12#[cfg(mobile)]
13mod mobile;
14
15mod commands;
16mod error;
17mod models;
18
19pub use error::{Error, Result};
20
21#[cfg(any(target_os = "windows", target_os = "linux"))]
22use desktop::Plauth;
23#[cfg(any(target_os = "macos"))]
24use macos::Plauth;
25#[cfg(mobile)]
26use mobile::Plauth;
27
28pub trait PlauthExt<R: Runtime> {
30 fn plauth(&self) -> &Plauth<R>;
31}
32
33impl<R: Runtime, T: Manager<R>> crate::PlauthExt<R> for T {
34 fn plauth(&self) -> &Plauth<R> {
35 self.state::<Plauth<R>>().inner()
36 }
37}
38
39pub fn init<R: Runtime>() -> TauriPlugin<R> {
41 Builder::new("plauth")
42 .invoke_handler(tauri::generate_handler![
43 commands::ping,
44 commands::authenticate
45 ])
46 .setup(|app, api| {
47 #[cfg(mobile)]
48 let plauth = mobile::init(app, api)?;
49 #[cfg(any(target_os = "windows", target_os = "linux"))]
50 let plauth = desktop::init(app, api)?;
51 #[cfg(target_os = "macos")]
52 let plauth = macos::init(app, api)?;
53 app.manage(plauth);
54 Ok(())
55 })
56 .build()
57}