Skip to main content

tauri_plugin_biometry/
lib.rs

1use 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;
20
21pub use error::{Error, Result};
22
23#[cfg(all(desktop, not(target_os = "windows"), not(target_os = "macos")))]
24use desktop::Biometry;
25#[cfg(target_os = "macos")]
26use macos::Biometry;
27#[cfg(mobile)]
28use mobile::Biometry;
29#[cfg(target_os = "windows")]
30use windows::Biometry;
31
32/// Extensions to [`tauri::App`], [`tauri::AppHandle`], [`tauri::WebviewWindow`], [`tauri::Webview`] and [`tauri::Window`] to access the biometry APIs.
33pub trait BiometryExt<R: Runtime> {
34    fn biometry(&self) -> &Biometry<R>;
35}
36
37impl<R: Runtime, T: Manager<R>> crate::BiometryExt<R> for T {
38    fn biometry(&self) -> &Biometry<R> {
39        self.state::<Biometry<R>>().inner()
40    }
41}
42
43/// Initializes the plugin.
44pub fn init<R: Runtime>() -> TauriPlugin<R> {
45    Builder::new("biometry")
46        .invoke_handler(tauri::generate_handler![
47            commands::status,
48            commands::authenticate,
49            commands::has_data,
50            commands::get_data,
51            commands::set_data,
52            commands::remove_data,
53        ])
54        .setup(|app, api| {
55            #[cfg(mobile)]
56            let biometry = mobile::init(app, api)?;
57            #[cfg(all(desktop, not(target_os = "windows"), not(target_os = "macos")))]
58            let biometry = desktop::init(app, api)?;
59            #[cfg(target_os = "windows")]
60            let biometry = windows::init(app, api)?;
61            #[cfg(target_os = "macos")]
62            let biometry = macos::init(app, api)?;
63            app.manage(biometry);
64            Ok(())
65        })
66        .build()
67}