cadmus_core/task/
auto_frontlight.rs1use std::sync::mpsc::Sender;
2use std::time::Duration;
3
4use crate::task::{BackgroundTask, ShutdownSignal, TaskId};
5use crate::view::Event;
6
7const CHECK_INTERVAL: Duration = Duration::from_secs(5 * 60);
8
9#[derive(Default)]
12pub struct AutoFrontlightTask;
13
14impl BackgroundTask for AutoFrontlightTask {
15 fn id(&self) -> TaskId {
16 TaskId::AutoFrontlight
17 }
18
19 fn run(&mut self, hub: &Sender<Event>, shutdown: &ShutdownSignal) {
20 while !shutdown.should_stop() {
21 if let Err(e) = hub.send(Event::UpdateAutoFrontlight) {
22 tracing::error!(error = %e, "failed to send auto-frontlight update event");
23 break;
24 }
25
26 if shutdown.wait(CHECK_INTERVAL) {
27 break;
28 }
29 }
30 }
31}