tauri_plugin_biometry/
lib.rs1use tauri::{
2 plugin::{Builder, TauriPlugin},
3 Manager, Runtime,
4};
5
6pub use models::*;
7
8#[cfg(all(desktop, not(target_os = "windows"), not(target_os = "macos")))]
9mod desktop;
10#[cfg(target_os = "macos")]
11mod macos;
12#[cfg(mobile)]
13mod mobile;
14#[cfg(target_os = "windows")]
15mod windows;
16
17mod commands;
18mod error;
19mod models;
20mod scope;
21
22pub use error::{Error, Result};
23pub use scope::Entry as ScopeEntry;
24
25#[cfg(all(desktop, not(target_os = "windows"), not(target_os = "macos")))]
26use desktop::Biometry;
27#[cfg(target_os = "macos")]
28use macos::Biometry;
29#[cfg(mobile)]
30use mobile::Biometry;
31#[cfg(target_os = "windows")]
32use windows::Biometry;
33
34pub trait BiometryExt<R: Runtime> {
36 fn biometry(&self) -> &Biometry<R>;
37}
38
39impl<R: Runtime, T: Manager<R>> crate::BiometryExt<R> for T {
40 fn biometry(&self) -> &Biometry<R> {
41 self.state::<Biometry<R>>().inner()
42 }
43}
44
45#[must_use]
47pub fn init<R: Runtime>() -> TauriPlugin<R> {
48 Builder::new("biometry")
49 .invoke_handler(tauri::generate_handler![
50 commands::status,
51 commands::authenticate,
52 commands::has_data,
53 commands::get_data,
54 commands::set_data,
55 commands::remove_data,
56 ])
57 .setup(|app, api| {
58 #[cfg(mobile)]
59 let biometry = mobile::init(app, api)?;
60 #[cfg(all(desktop, not(target_os = "windows"), not(target_os = "macos")))]
61 let biometry = desktop::init(app, api)?;
62 #[cfg(target_os = "windows")]
63 let biometry = windows::init(app, api)?;
64 #[cfg(target_os = "macos")]
65 let biometry = macos::init(app, api)?;
66 app.manage(biometry);
67 Ok(())
68 })
69 .build()
70}