@@ -2,11 +2,9 @@ use std::{
22 fs:: { self } ,
33 sync:: Mutex ,
44 thread,
5- time:: Duration ,
5+ time:: { Duration , Instant } ,
66} ;
77
8- use chrono:: { DateTime , Local } ;
9-
108use crate :: acpi:: { BacklightAcpiDevice , ACPI_DEVICES_PATH } ;
119use crate :: ddc:: BacklightDdcDevice ;
1210
@@ -17,7 +15,7 @@ use crate::ddc::BacklightDdcDevice;
1715static MONITORS : Mutex < Vec < Box < dyn BacklightDevice + Send > > > = Mutex :: new ( Vec :: new ( ) ) ;
1816
1917/// The last time the list of known monitors was refreshed.
20- static LAST_REFRESH : Mutex < Option < DateTime < Local > > > = Mutex :: new ( None ) ;
18+ static LAST_REFRESH : Mutex < Option < Instant > > = Mutex :: new ( None ) ;
2119
2220/// The frequency at which the list of known monitors must be refreshed.
2321const MONITORS_REFRESH_INTERVAL : Duration = Duration :: from_secs ( 60 ) ;
@@ -36,12 +34,7 @@ pub(crate) fn auto_refresh_monitors_list() -> ! {
3634 . expect ( "Unable to acquire LAST_REFRESH mutex" ) ;
3735
3836 last_refresh. is_none ( )
39- || last_refresh. is_some_and ( |dt| {
40- ( Local :: now ( ) - dt)
41- . to_std ( )
42- . unwrap_or ( MONITORS_REFRESH_INTERVAL + Duration :: from_secs ( 1 ) )
43- > MONITORS_REFRESH_INTERVAL
44- } )
37+ || last_refresh. is_some_and ( |dt| Instant :: now ( ) - dt > MONITORS_REFRESH_INTERVAL )
4538 } ;
4639
4740 if must_refresh {
@@ -89,7 +82,7 @@ pub(crate) fn refresh_monitors_list() {
8982
9083 * LAST_REFRESH
9184 . lock ( )
92- . expect ( "Unable to acquire LAST_REFRESH mutex" ) = Some ( Local :: now ( ) ) ;
85+ . expect ( "Unable to acquire LAST_REFRESH mutex" ) = Some ( Instant :: now ( ) ) ;
9386}
9487
9588pub ( crate ) fn set_brightness_percent ( percent : u8 ) -> anyhow:: Result < ( ) > {
0 commit comments