1- use std:: { str:: FromStr , sync:: { Arc , Mutex } , time:: { self , Duration } } ;
1+ use std:: { fmt :: Display , str:: FromStr , sync:: { Arc , Mutex } , time:: { self , Duration } } ;
22
33use dbus:: { arg:: ReadAll , blocking:: { Connection , Proxy } , message:: SignalArgs , Message , Path } ;
44
@@ -56,18 +56,18 @@ impl FromStr for Status {
5656 }
5757}
5858
59- impl ToString for Status {
60- fn to_string ( & self ) -> String {
59+ impl Display for Status {
60+ fn fmt ( & self , f : & mut std :: fmt :: Formatter < ' _ > ) -> std :: fmt :: Result {
6161 match self {
62- Status :: Match => "verify-match" ,
63- Status :: NoMatch => "verify-no-match" ,
64- Status :: RetryScan => "verify-retry-scan" ,
65- Status :: SwipeTooShort => "verify-swipe-too-short" ,
66- Status :: FingerNotCentered => "verify-finger-not-entered" ,
67- Status :: RemoveAndRetry => "verify-remove-and-retry" ,
68- Status :: Disconnected => "verify-disconnected" ,
69- Status :: UnknownError => "verify-unknown-error" ,
70- } . to_string ( )
62+ Status :: Match => f . write_str ( "verify-match" ) ,
63+ Status :: NoMatch => f . write_str ( "verify-no-match" ) ,
64+ Status :: RetryScan => f . write_str ( "verify-retry-scan" ) ,
65+ Status :: SwipeTooShort => f . write_str ( "verify-swipe-too-short" ) ,
66+ Status :: FingerNotCentered => f . write_str ( "verify-finger-not-entered" ) ,
67+ Status :: RemoveAndRetry => f . write_str ( "verify-remove-and-retry" ) ,
68+ Status :: Disconnected => f . write_str ( "verify-disconnected" ) ,
69+ Status :: UnknownError => f . write_str ( "verify-unknown-error" ) ,
70+ }
7171 }
7272}
7373
@@ -126,37 +126,34 @@ impl <'a> FprintDevice<'a> {
126126 let t1 = time:: Instant :: now ( ) ;
127127 time_left -= ( t1 - t0) . as_millis ( ) as i64 ;
128128
129- match * scan_status_clone. lock ( ) . unwrap ( ) {
130- Some ( status) => {
131- match status {
132- Status :: Match => {
133- self . proxy . method_call ( FPRINTD_DEVICE_IFACE , "VerifyStop" , ( ) )
134- . or ( fail ( "fprintd: unable to stop fingerprint verification" ) ) ?;
135- return Ok ( true )
136- } ,
137- Status :: NoMatch => {
138- eprintln ! ( "fingerprint not recognized, try again" ) ;
139- self . proxy . method_call ( FPRINTD_DEVICE_IFACE , "VerifyStop" , ( ) )
140- . or ( fail ( "fprintd: unable to stop fingerprint verification" ) ) ?;
141- self . proxy . method_call ( FPRINTD_DEVICE_IFACE , "VerifyStart" , ( "any" , ) )
142- . or ( fail ( "fprintd: unable to restart fingerprint verification" ) ) ?;
143- } ,
144- Status :: RetryScan | Status :: SwipeTooShort | Status :: FingerNotCentered | Status :: RemoveAndRetry => {
145- eprintln ! ( "fingerprint not recognized, try again" )
146- // scan is still ongoing, keep waiting for status updates
147- } ,
148- Status :: Disconnected => {
149- return fail ( "fprintd: fingerprint reader disconnected" )
150- } ,
151- Status :: UnknownError => {
152- self . proxy . method_call ( FPRINTD_DEVICE_IFACE , "VerifyStop" , ( ) )
153- . or ( fail ( "fprintd: unable to stop fingerprint verification" ) ) ?;
154- return fail ( "fprintd: fingerprint scan failed with unknown error" )
155- } ,
156- }
157-
158- } ,
159- None => { } ,
129+ if let Some ( status) = * scan_status_clone. lock ( ) . unwrap ( ) {
130+ match status {
131+ Status :: Match => {
132+ self . proxy . method_call ( FPRINTD_DEVICE_IFACE , "VerifyStop" , ( ) )
133+ . or ( fail ( "fprintd: unable to stop fingerprint verification" ) ) ?;
134+ return Ok ( true )
135+ } ,
136+ Status :: NoMatch => {
137+ eprintln ! ( "fingerprint not recognized, try again" ) ;
138+ self . proxy . method_call ( FPRINTD_DEVICE_IFACE , "VerifyStop" , ( ) )
139+ . or ( fail ( "fprintd: unable to stop fingerprint verification" ) ) ?;
140+ self . proxy . method_call ( FPRINTD_DEVICE_IFACE , "VerifyStart" , ( "any" , ) )
141+ . or ( fail ( "fprintd: unable to restart fingerprint verification" ) ) ?;
142+ } ,
143+ Status :: RetryScan | Status :: SwipeTooShort | Status :: FingerNotCentered | Status :: RemoveAndRetry => {
144+ eprintln ! ( "fingerprint not recognized, try again" )
145+ // scan is still ongoing, keep waiting for status updates
146+ } ,
147+ Status :: Disconnected => {
148+ return fail ( "fprintd: fingerprint reader disconnected" )
149+ } ,
150+ Status :: UnknownError => {
151+ self . proxy . method_call ( FPRINTD_DEVICE_IFACE , "VerifyStop" , ( ) )
152+ . or ( fail ( "fprintd: unable to stop fingerprint verification" ) ) ?;
153+ return fail ( "fprintd: fingerprint scan failed with unknown error" )
154+ } ,
155+ }
156+
160157 }
161158 }
162159 self . proxy . method_call ( FPRINTD_DEVICE_IFACE , "VerifyStop" , ( ) )
@@ -180,7 +177,7 @@ impl <'a> FprintDevice<'a> {
180177 ) ;
181178 proxy. method_call ( FPRINTD_DEVICE_IFACE , "Claim" , ( "" , ) )
182179 . or ( Err ( super :: Error :: ImplementationSpecificError ( "fprintd: unable to claim device" . to_owned ( ) ) ) ) ?;
183- Ok ( FprintDevice { proxy : proxy , connection : conn } )
180+ Ok ( FprintDevice { proxy, connection : conn } )
184181 }
185182}
186183
0 commit comments