Fix biometric
This commit is contained in:
parent
59137ea7c6
commit
d6cbd2c00e
|
@ -21,10 +21,9 @@ features = ["napi-6", "promise-api", "task-api"]
|
|||
[target.'cfg(windows)'.dependencies.windows]
|
||||
version = "0.32.0"
|
||||
features = [
|
||||
"alloc",
|
||||
"Foundation",
|
||||
"Security_Credentials_UI",
|
||||
"Win32_Foundation",
|
||||
"Win32_Security_Cryptography_UI",
|
||||
"Win32_System_Com",
|
||||
"Win32_System_WinRT"
|
||||
"Win32_System_WinRT",
|
||||
]
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#[cfg(windows)]
|
||||
use win as imp;
|
||||
#[cfg(target_os = "macos")]
|
||||
use mac as imp;
|
||||
#[cfg(not(any(target_os = "macos", windows)))]
|
||||
use unix as imp;
|
||||
#[cfg(windows)]
|
||||
use win as imp;
|
||||
|
||||
#[cfg(any(target_os = "redox", unix))]
|
||||
mod unix;
|
||||
|
@ -16,6 +16,9 @@ pub async fn available() -> bool {
|
|||
imp::available().await
|
||||
}
|
||||
|
||||
pub fn verify() -> bool {
|
||||
imp::verify()
|
||||
pub async fn verify(
|
||||
message: &str,
|
||||
window_handle: isize,
|
||||
) -> Result<bool, Box<dyn std::error::Error + Send + Sync>> {
|
||||
imp::verify(message, window_handle).await
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
use windows::Security::Credentials::UI::*;
|
||||
use windows::Win32::System::WinRT::IUserConsentVerifierInterop;
|
||||
use windows::Win32::Foundation::HWND;
|
||||
use windows::{core::*, Win32::System::Com::*};
|
||||
use windows::core::*;
|
||||
use windows::Foundation::IAsyncOperation;
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
use windows::Security::Credentials::UI::*;
|
||||
use windows::Win32::Foundation::HWND;
|
||||
use windows::Win32::System::WinRT::IUserConsentVerifierInterop;
|
||||
|
||||
pub async fn available() -> bool {
|
||||
let event = UserConsentVerifier::CheckAvailabilityAsync();
|
||||
|
@ -18,37 +16,38 @@ pub async fn available() -> bool {
|
|||
Ok(t) => match t {
|
||||
UserConsentVerifierAvailability::Available => true,
|
||||
UserConsentVerifierAvailability::DeviceBusy => true,
|
||||
_ => false
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn verify() -> bool {
|
||||
Runtime::new().unwrap().block_on(available());
|
||||
println!("HI");
|
||||
let message = HSTRING::from("hello world");
|
||||
pub async fn verify(
|
||||
message: &str,
|
||||
window_handle: isize,
|
||||
) -> std::result::Result<bool, Box<dyn std::error::Error + Send + Sync>> {
|
||||
let interop: IUserConsentVerifierInterop =
|
||||
match factory::<UserConsentVerifier, IUserConsentVerifierInterop>() {
|
||||
Ok(i) => i,
|
||||
Err(e) => return Err(e.into()),
|
||||
};
|
||||
|
||||
unsafe { CoInitializeEx(std::ptr::null(), COINIT_MULTITHREADED).unwrap() };
|
||||
let window = HWND(window_handle);
|
||||
|
||||
let hw: HWND = HWND::default();
|
||||
let verifier: IUserConsentVerifierInterop = unsafe { CoCreateInstance(&IUserConsentVerifierInterop::IID, None, CLSCTX_ALL).unwrap() };
|
||||
let test: Result<IAsyncOperation<UserConsentVerificationResult>> = unsafe { verifier.RequestVerificationForWindowAsync(hw, message) };
|
||||
println!("{:?}", test);
|
||||
/*
|
||||
let result = match event {
|
||||
Err(_) => return false,
|
||||
Ok(t) => t.await,
|
||||
let operation: Result<IAsyncOperation<UserConsentVerificationResult>> =
|
||||
unsafe { interop.RequestVerificationForWindowAsync(window, message) };
|
||||
|
||||
let result = match operation {
|
||||
Ok(r) => r.await,
|
||||
Err(e) => return Err(e.into()),
|
||||
};
|
||||
|
||||
match result {
|
||||
Err(_) => false,
|
||||
Err(e) => return Err(e.into()),
|
||||
Ok(t) => match t {
|
||||
UserConsentVerificationResult::Verified => true,
|
||||
_ => false
|
||||
}
|
||||
UserConsentVerificationResult::Verified => Ok(true),
|
||||
_ => Ok(false),
|
||||
},
|
||||
}
|
||||
*/
|
||||
false
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -62,7 +61,6 @@ mod tests {
|
|||
#[test]
|
||||
fn verify() {
|
||||
// TODO Mock!
|
||||
assert_eq!(true, super::verify())
|
||||
//assert_eq!(true, super::verify("test", 0))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,16 @@ fn supports_biometric(mut cx: FunctionContext) -> JsResult<JsPromise> {
|
|||
}
|
||||
|
||||
fn verify(mut cx: FunctionContext) -> JsResult<JsPromise> {
|
||||
let message = cx.argument::<JsString>(0)?.value(&mut cx);
|
||||
let window_handle = cx.argument::<JsNumber>(1)?.value(&mut cx) as isize;
|
||||
|
||||
let promise = cx
|
||||
.task(move || biometric::verify())
|
||||
.task(move || {
|
||||
Runtime::new()
|
||||
.unwrap()
|
||||
.block_on(biometric::verify(&message, window_handle))
|
||||
.unwrap()
|
||||
})
|
||||
.promise(|mut cx, n| Ok(cx.boolean(n)));
|
||||
|
||||
Ok(promise)
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
use windows::Security::Credentials::UI::*;
|
||||
use windows::Win32::System::WinRT::IUserConsentVerifierInterop;
|
||||
use windows::Win32::Foundation::HWND;
|
||||
use windows::{core::*, Win32::System::Com::*};
|
||||
use windows::Foundation::IAsyncOperation;
|
||||
|
||||
fn main() {
|
||||
unsafe { CoInitializeEx(std::ptr::null(), COINIT_MULTITHREADED).unwrap() };
|
||||
|
||||
let message = HSTRING::from("hello world");
|
||||
let hw: HWND = HWND::default();
|
||||
|
||||
let verifier: IUserConsentVerifierInterop = unsafe { CoCreateInstance(&IUserConsentVerifierInterop::IID, None, CLSCTX_ALL).unwrap() };
|
||||
let test: Result<IAsyncOperation<UserConsentVerificationResult>> = unsafe { verifier.RequestVerificationForWindowAsync(hw, message) };
|
||||
}
|
Loading…
Reference in New Issue