pull/829/head
Lucas Nogueira 2 years ago
parent 7f910323fc
commit 85c918eb8d
No known key found for this signature in database
GPG Key ID: 3AFF5CAD641DD470

1
Cargo.lock generated

@ -5699,6 +5699,7 @@ dependencies = [
"log", "log",
"serde", "serde",
"serde_json", "serde_json",
"serde_repr",
"tauri", "tauri",
"tauri-build", "tauri-build",
"thiserror", "thiserror",

@ -1,116 +1,116 @@
{ {
"images" : [ "images": [
{ {
"size" : "20x20", "size": "20x20",
"idiom" : "iphone", "idiom": "iphone",
"filename" : "AppIcon-20x20@2x.png", "filename": "AppIcon-20x20@2x.png",
"scale" : "2x" "scale": "2x"
}, },
{ {
"size" : "20x20", "size": "20x20",
"idiom" : "iphone", "idiom": "iphone",
"filename" : "AppIcon-20x20@3x.png", "filename": "AppIcon-20x20@3x.png",
"scale" : "3x" "scale": "3x"
}, },
{ {
"size" : "29x29", "size": "29x29",
"idiom" : "iphone", "idiom": "iphone",
"filename" : "AppIcon-29x29@2x-1.png", "filename": "AppIcon-29x29@2x-1.png",
"scale" : "2x" "scale": "2x"
}, },
{ {
"size" : "29x29", "size": "29x29",
"idiom" : "iphone", "idiom": "iphone",
"filename" : "AppIcon-29x29@3x.png", "filename": "AppIcon-29x29@3x.png",
"scale" : "3x" "scale": "3x"
}, },
{ {
"size" : "40x40", "size": "40x40",
"idiom" : "iphone", "idiom": "iphone",
"filename" : "AppIcon-40x40@2x.png", "filename": "AppIcon-40x40@2x.png",
"scale" : "2x" "scale": "2x"
}, },
{ {
"size" : "40x40", "size": "40x40",
"idiom" : "iphone", "idiom": "iphone",
"filename" : "AppIcon-40x40@3x.png", "filename": "AppIcon-40x40@3x.png",
"scale" : "3x" "scale": "3x"
}, },
{ {
"size" : "60x60", "size": "60x60",
"idiom" : "iphone", "idiom": "iphone",
"filename" : "AppIcon-60x60@2x.png", "filename": "AppIcon-60x60@2x.png",
"scale" : "2x" "scale": "2x"
}, },
{ {
"size" : "60x60", "size": "60x60",
"idiom" : "iphone", "idiom": "iphone",
"filename" : "AppIcon-60x60@3x.png", "filename": "AppIcon-60x60@3x.png",
"scale" : "3x" "scale": "3x"
}, },
{ {
"size" : "20x20", "size": "20x20",
"idiom" : "ipad", "idiom": "ipad",
"filename" : "AppIcon-20x20@1x.png", "filename": "AppIcon-20x20@1x.png",
"scale" : "1x" "scale": "1x"
}, },
{ {
"size" : "20x20", "size": "20x20",
"idiom" : "ipad", "idiom": "ipad",
"filename" : "AppIcon-20x20@2x-1.png", "filename": "AppIcon-20x20@2x-1.png",
"scale" : "2x" "scale": "2x"
}, },
{ {
"size" : "29x29", "size": "29x29",
"idiom" : "ipad", "idiom": "ipad",
"filename" : "AppIcon-29x29@1x.png", "filename": "AppIcon-29x29@1x.png",
"scale" : "1x" "scale": "1x"
}, },
{ {
"size" : "29x29", "size": "29x29",
"idiom" : "ipad", "idiom": "ipad",
"filename" : "AppIcon-29x29@2x.png", "filename": "AppIcon-29x29@2x.png",
"scale" : "2x" "scale": "2x"
}, },
{ {
"size" : "40x40", "size": "40x40",
"idiom" : "ipad", "idiom": "ipad",
"filename" : "AppIcon-40x40@1x.png", "filename": "AppIcon-40x40@1x.png",
"scale" : "1x" "scale": "1x"
}, },
{ {
"size" : "40x40", "size": "40x40",
"idiom" : "ipad", "idiom": "ipad",
"filename" : "AppIcon-40x40@2x-1.png", "filename": "AppIcon-40x40@2x-1.png",
"scale" : "2x" "scale": "2x"
}, },
{ {
"size" : "76x76", "size": "76x76",
"idiom" : "ipad", "idiom": "ipad",
"filename" : "AppIcon-76x76@1x.png", "filename": "AppIcon-76x76@1x.png",
"scale" : "1x" "scale": "1x"
}, },
{ {
"size" : "76x76", "size": "76x76",
"idiom" : "ipad", "idiom": "ipad",
"filename" : "AppIcon-76x76@2x.png", "filename": "AppIcon-76x76@2x.png",
"scale" : "2x" "scale": "2x"
}, },
{ {
"size" : "83.5x83.5", "size": "83.5x83.5",
"idiom" : "ipad", "idiom": "ipad",
"filename" : "AppIcon-83.5x83.5@2x.png", "filename": "AppIcon-83.5x83.5@2x.png",
"scale" : "2x" "scale": "2x"
}, },
{ {
"size" : "1024x1024", "size": "1024x1024",
"idiom" : "ios-marketing", "idiom": "ios-marketing",
"filename" : "AppIcon-512@2x.png", "filename": "AppIcon-512@2x.png",
"scale" : "1x" "scale": "1x"
} }
], ],
"info" : { "info": {
"version" : 1, "version": 1,
"author" : "xcode" "author": "xcode"
} }
} }

@ -1,6 +1,6 @@
{ {
"info" : { "info": {
"version" : 1, "version": 1,
"author" : "xcode" "author": "xcode"
} }
} }

@ -20,3 +20,4 @@ serde_json = { workspace = true }
tauri = { workspace = true } tauri = { workspace = true }
log = { workspace = true } log = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
serde_repr = "0.1"

@ -2,4 +2,52 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
export async function doSomething() {} declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
export enum BiometryType {
None = 0,
TouchID = 1,
FaceID = 2,
}
export interface Status {
isAvailable: boolean;
biometryType: BiometryType;
error?: string;
errorCode?:
| "appCancel"
| "authenticationFailed"
| "invalidContext"
| "notInteractive"
| "passcodeNotSet"
| "systemCancel"
| "userCancel"
| "userFallback"
| "biometryLockout"
| "biometryNotAvailable"
| "biometryNotEnrolled";
}
export interface AuthOptions {
fallbackTitle?: string;
cancelTitle?: string;
allowDeviceCredential?: boolean;
}
export async function checkStatus(): Promise<Status> {
return window.__TAURI_INVOKE__("plugin:biometry|status");
}
export async function authenticate(
reason: string,
options?: AuthOptions,
): Promise<void> {
return window.__TAURI_INVOKE__("plugin:biometry|authenticate", {
reason,
...options,
});
}

@ -84,8 +84,8 @@ class BiometricPlugin: Plugin {
invoke.resolve([ invoke.resolve([
"isAvailable": self.status.available, "isAvailable": self.status.available,
"biometryType": self.status.biometryType.rawValue, "biometryType": self.status.biometryType.rawValue,
"reason": self.status.errorReason ?? "", "error": self.status.errorReason ?? "",
"code": self.status.errorCode ?? "", "errorCode": self.status.errorCode ?? "",
]) ])
} }
} }

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_BIOMETRIC__=function(_){"use strict";return _.doSomething=async function(){},_}({});Object.defineProperty(window.__TAURI__,"biometric",{value:__TAURI_BIOMETRIC__})} if("__TAURI__"in window){var __TAURI_BIOMETRIC__=function(e){"use strict";var _;return e.BiometryType=void 0,(_=e.BiometryType||(e.BiometryType={}))[_.None=0]="None",_[_.TouchID=1]="TouchID",_[_.FaceID=2]="FaceID",e.authenticate=async function(e,_){return window.__TAURI_INVOKE__("plugin:biometry|authenticate",{reason:e,..._})},e.checkStatus=async function(){return window.__TAURI_INVOKE__("plugin:biometry|status")},e}({});Object.defineProperty(window.__TAURI__,"biometric",{value:__TAURI_BIOMETRIC__})}

@ -1,15 +0,0 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use tauri::{AppHandle, command, Runtime, Window};
use crate::Result;
#[command]
pub(crate) async fn execute<R: Runtime>(
_app: AppHandle<R>,
_window: Window<R>,
) -> Result<String> {
Ok("success".to_string())
}

@ -4,6 +4,7 @@
#![cfg(mobile)] #![cfg(mobile)]
use serde::Serialize;
use tauri::{ use tauri::{
plugin::{Builder, PluginHandle, TauriPlugin}, plugin::{Builder, PluginHandle, TauriPlugin},
Manager, Runtime, Manager, Runtime,
@ -11,7 +12,6 @@ use tauri::{
pub use models::*; pub use models::*;
mod commands;
mod error; mod error;
mod models; mod models;
@ -26,10 +26,21 @@ tauri::ios_plugin_binding!(init_plugin_biometric);
/// Access to the biometric APIs. /// Access to the biometric APIs.
pub struct Biometric<R: Runtime>(PluginHandle<R>); pub struct Biometric<R: Runtime>(PluginHandle<R>);
#[derive(Serialize)]
struct AuthenticatePayload {
reason: String,
#[serde(flatten)]
options: AuthOptions,
}
impl<R: Runtime> Biometric<R> { impl<R: Runtime> Biometric<R> {
pub fn ping(&self, payload: PingRequest) -> crate::Result<PingResponse> { pub fn status(&self) -> crate::Result<Status> {
self.0.run_mobile_plugin("status", ()).map_err(Into::into)
}
pub fn authenticate(&self, reason: String, options: AuthOptions) -> crate::Result<()> {
self.0 self.0
.run_mobile_plugin("ping", payload) .run_mobile_plugin("authenticate", AuthenticatePayload { reason, options })
.map_err(Into::into) .map_err(Into::into)
} }
} }
@ -49,7 +60,6 @@ impl<R: Runtime, T: Manager<R>> crate::BiometricExt<R> for T {
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("biometric") Builder::new("biometric")
.js_init_script(include_str!("api-iife.js").to_string()) .js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![commands::execute])
.setup(|app, api| { .setup(|app, api| {
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "BiometricPlugin")?; let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "BiometricPlugin")?;

@ -4,14 +4,27 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize)] #[derive(Debug, Default, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct PingRequest { pub struct AuthOptions {
pub value: Option<String>, pub fallback_title: Option<String>,
pub cancel_title: Option<String>,
pub allow_device_credential: bool,
} }
#[derive(Debug, Clone, Default, Deserialize)] #[derive(Debug, Clone, serde_repr::Deserialize_repr)]
#[repr(u8)]
pub enum BiometryType {
None = 0,
TouchID = 1,
FaceID = 2,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct PingResponse { pub struct Status {
pub value: Option<String>, pub is_available: bool,
pub biometry_type: BiometryType,
pub error: Option<String>,
pub error_code: Option<String>,
} }

Loading…
Cancel
Save