Skip to content

Commit 1ccfd79

Browse files
committed
monitors.rs : use std::time::Instant instead of chrono::DateTime
1 parent 6152438 commit 1ccfd79

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

backlightd/src/monitors.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
108
use crate::acpi::{BacklightAcpiDevice, ACPI_DEVICES_PATH};
119
use crate::ddc::BacklightDdcDevice;
1210

@@ -17,7 +15,7 @@ use crate::ddc::BacklightDdcDevice;
1715
static 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.
2321
const 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

9588
pub(crate) fn set_brightness_percent(percent: u8) -> anyhow::Result<()> {

0 commit comments

Comments
 (0)