Skip to content

Commit f0e861f

Browse files
committed
Cleanup
1 parent f47a3f5 commit f0e861f

File tree

2 files changed

+17
-30
lines changed

2 files changed

+17
-30
lines changed

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ pub use models::*;
77

88
#[cfg(all(desktop, not(target_os = "windows")))]
99
mod desktop;
10-
#[cfg(target_os = "windows")]
11-
mod windows;
1210
#[cfg(mobile)]
1311
mod mobile;
12+
#[cfg(target_os = "windows")]
13+
mod windows;
1414

1515
mod commands;
1616
mod error;
@@ -20,10 +20,10 @@ pub use error::{Error, Result};
2020

2121
#[cfg(all(desktop, not(target_os = "windows")))]
2222
use desktop::Biometry;
23-
#[cfg(target_os = "windows")]
24-
use windows::Biometry;
2523
#[cfg(mobile)]
2624
use mobile::Biometry;
25+
#[cfg(target_os = "windows")]
26+
use windows::Biometry;
2727

2828
/// Extensions to [`tauri::App`], [`tauri::AppHandle`], [`tauri::WebviewWindow`], [`tauri::Webview`] and [`tauri::Window`] to access the biometry APIs.
2929
pub trait BiometryExt<R: Runtime> {

src/windows.rs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ use windows::{
88
Security::Credentials::UI::{
99
UserConsentVerificationResult, UserConsentVerifier, UserConsentVerifierAvailability,
1010
},
11-
Win32::{
12-
UI::WindowsAndMessaging::{
13-
BringWindowToTop, FindWindowW, IsIconic, SetForegroundWindow, ShowWindow, SW_RESTORE,
14-
},
11+
Win32::UI::WindowsAndMessaging::{
12+
BringWindowToTop, FindWindowW, IsIconic, SetForegroundWindow, ShowWindow, SW_RESTORE,
1513
},
1614
};
1715

@@ -40,8 +38,7 @@ fn try_focus_hello_dialog_once() -> bool {
4038
windows::core::PCWSTR(cls.as_ptr()),
4139
windows::core::PCWSTR::null(),
4240
);
43-
if hwnd.is_ok() {
44-
let hwnd = hwnd.unwrap();
41+
if let Ok(hwnd) = hwnd {
4542
if IsIconic(hwnd).as_bool() {
4643
let _ = ShowWindow(hwnd, SW_RESTORE);
4744
}
@@ -75,8 +72,7 @@ impl<R: Runtime> Biometry<R> {
7572
let availability = UserConsentVerifier::CheckAvailabilityAsync()
7673
.and_then(|async_op| async_op.get())
7774
.map_err(|e| {
78-
crate::Error::from(std::io::Error::new(
79-
std::io::ErrorKind::Other,
75+
crate::Error::from(std::io::Error::other(
8076
format!("Failed to check biometry availability: {:?}", e),
8177
))
8278
})?;
@@ -130,35 +126,27 @@ impl<R: Runtime> Biometry<R> {
130126
async_op.get()
131127
})
132128
.map_err(|e| {
133-
crate::Error::from(std::io::Error::new(
134-
std::io::ErrorKind::Other,
129+
crate::Error::from(std::io::Error::other(
135130
format!("Failed to request user verification: {:?}", e),
136131
))
137132
})?;
138133

139134
match result {
140135
UserConsentVerificationResult::Verified => Ok(()),
141-
UserConsentVerificationResult::DeviceBusy => {
142-
Err(crate::Error::from(std::io::Error::new(
143-
std::io::ErrorKind::ResourceBusy,
144-
"Device is busy",
145-
)))
146-
}
147-
UserConsentVerificationResult::DeviceNotPresent => {
148-
Err(crate::Error::from(std::io::Error::new(
149-
std::io::ErrorKind::NotFound,
150-
"No biometric device found",
151-
)))
152-
}
136+
UserConsentVerificationResult::DeviceBusy => Err(crate::Error::from(
137+
std::io::Error::new(std::io::ErrorKind::ResourceBusy, "Device is busy"),
138+
)),
139+
UserConsentVerificationResult::DeviceNotPresent => Err(crate::Error::from(
140+
std::io::Error::new(std::io::ErrorKind::NotFound, "No biometric device found"),
141+
)),
153142
UserConsentVerificationResult::DisabledByPolicy => {
154143
Err(crate::Error::from(std::io::Error::new(
155144
std::io::ErrorKind::PermissionDenied,
156145
"Biometric authentication is disabled by policy",
157146
)))
158147
}
159148
UserConsentVerificationResult::NotConfiguredForUser => {
160-
Err(crate::Error::from(std::io::Error::new(
161-
std::io::ErrorKind::Other,
149+
Err(crate::Error::from(std::io::Error::other(
162150
"Biometric authentication is not configured for the user",
163151
)))
164152
}
@@ -174,8 +162,7 @@ impl<R: Runtime> Biometry<R> {
174162
"Too many failed authentication attempts",
175163
)))
176164
}
177-
_ => Err(crate::Error::from(std::io::Error::new(
178-
std::io::ErrorKind::Other,
165+
_ => Err(crate::Error::from(std::io::Error::other(
179166
"Authentication failed",
180167
))),
181168
}

0 commit comments

Comments
 (0)