mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-22 21:30:44 +02:00
chore: update documentation
This commit is contained in:
@@ -4,12 +4,18 @@
|
||||
|
||||
use serde::{ser::Serializer, Serialize};
|
||||
|
||||
/// Alias for a [`Result`](std::result::Result) with the error type [`Error`].
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
/// The error types returned by this plugin.
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
/// An I/O error occurred.
|
||||
#[error(transparent)]
|
||||
Io(#[from] std::io::Error),
|
||||
/// The invocation of the underlying Android or iOS plugin failed, for example because
|
||||
/// biometric authentication was unavailable, was not enrolled, failed, or was canceled by
|
||||
/// the user.
|
||||
#[cfg(mobile)]
|
||||
#[error(transparent)]
|
||||
PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//! Prompt the user for biometric authentication.
|
||||
//!
|
||||
//! - Supported platforms: Android and iOS.
|
||||
|
||||
#![cfg(mobile)]
|
||||
|
||||
use serde::Serialize;
|
||||
@@ -34,10 +38,16 @@ struct AuthenticatePayload {
|
||||
}
|
||||
|
||||
impl<R: Runtime> Biometric<R> {
|
||||
/// Checks the device's availability and type of biometric authentication, as reported by the
|
||||
/// operating system. Errors if the underlying mobile plugin invocation fails.
|
||||
pub fn status(&self) -> crate::Result<Status> {
|
||||
self.0.run_mobile_plugin("status", ()).map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Prompts the user for biometric authentication using the system UI (Android
|
||||
/// `BiometricPrompt` or iOS `LocalAuthentication`), showing `reason` as the purpose of the
|
||||
/// request. Resolves once the user is authenticated and errors if authentication fails, is
|
||||
/// canceled, or the underlying mobile plugin invocation fails.
|
||||
pub fn authenticate(&self, reason: String, options: AuthOptions) -> crate::Result<()> {
|
||||
self.0
|
||||
.run_mobile_plugin("authenticate", AuthenticatePayload { reason, options })
|
||||
@@ -47,6 +57,7 @@ impl<R: Runtime> Biometric<R> {
|
||||
|
||||
/// Extensions to [`tauri::App`], [`tauri::AppHandle`], [`tauri::WebviewWindow`], [`tauri::Webview`] and [`tauri::Window`] to access the biometric APIs.
|
||||
pub trait BiometricExt<R: Runtime> {
|
||||
/// Returns the [`Biometric`] instance managed by the app.
|
||||
fn biometric(&self) -> &Biometric<R>;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Options for [`Biometric::authenticate`](crate::Biometric::authenticate).
|
||||
#[derive(Debug, Default, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AuthOptions {
|
||||
@@ -21,19 +22,31 @@ pub struct AuthOptions {
|
||||
pub confirmation_required: Option<bool>,
|
||||
}
|
||||
|
||||
/// The kind of biometry hardware detected on the device.
|
||||
#[derive(Debug, Clone, serde_repr::Deserialize_repr)]
|
||||
#[repr(u8)]
|
||||
pub enum BiometryType {
|
||||
/// No biometry hardware is available, or it is not enrolled with the operating system.
|
||||
None = 0,
|
||||
/// Fingerprint authentication (Apple Touch ID or Android fingerprint).
|
||||
TouchID = 1,
|
||||
/// Face authentication (Apple Face ID or Android face authentication).
|
||||
FaceID = 2,
|
||||
}
|
||||
|
||||
/// The result of [`Biometric::status`](crate::Biometric::status), describing whether biometric
|
||||
/// authentication can currently be used.
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Status {
|
||||
/// Whether the device can currently authenticate using biometrics.
|
||||
pub is_available: bool,
|
||||
/// The kind of biometry hardware detected on the device, even when [`Self::is_available`] is `false`.
|
||||
pub biometry_type: BiometryType,
|
||||
/// A human-readable reason why biometric authentication is unavailable. Only set when
|
||||
/// [`Self::is_available`] is `false`.
|
||||
pub error: Option<String>,
|
||||
/// A platform-specific error code describing why biometric authentication is unavailable.
|
||||
/// Only set when [`Self::is_available`] is `false`.
|
||||
pub error_code: Option<String>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user