a lightweight, interval-based utility to combat digital strain through "Ma" (intentional pauses) for the eyes and body.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: overlay and multimonitor get enforce state check

+15 -8
+7
src/overlay/mod.rs
··· 5 5 pub mod password; 6 6 pub mod session; 7 7 8 + use std::sync::atomic::{AtomicBool, Ordering}; 8 9 use std::sync::{Arc, Mutex}; 9 10 use std::time::Duration; 10 11 ··· 31 32 pub struct OverlayManager { 32 33 backend: Box<dyn OverlayBackend>, 33 34 is_dark: bool, 35 + is_enforced: Arc<AtomicBool>, 34 36 cmd_tx: tokio::sync::mpsc::UnboundedSender<TimerCommand>, 35 37 cfg_arc: Arc<Mutex<AppConfig>>, 36 38 known_monitors: Vec<monitors::MonitorInfo>, ··· 69 71 None 70 72 }; 71 73 74 + let is_enforced = Arc::new(AtomicBool::new(false)); 72 75 let backend = Box::new(multi_slint::MultiSlintBackend::new( 73 76 is_dark, 74 77 &all_monitors, 75 78 cmd_tx.clone(), 76 79 cfg_arc.clone(), 80 + Arc::clone(&is_enforced), 77 81 )?); 78 82 79 83 Ok(Self { 80 84 backend, 81 85 is_dark, 86 + is_enforced, 82 87 cmd_tx, 83 88 cfg_arc, 84 89 known_monitors: all_monitors, ··· 90 95 } 91 96 92 97 pub fn show_break(&self, sched: &ScheduledBreak, is_enforced: bool, snooze_used: bool) { 98 + self.is_enforced.store(is_enforced, Ordering::Relaxed); 93 99 self.backend.show_break(sched, is_enforced, snooze_used); 94 100 #[cfg(target_os = "linux")] 95 101 if let Some(ref b) = self.layer_barrier { ··· 162 168 &self.known_monitors, 163 169 self.cmd_tx.clone(), 164 170 self.cfg_arc.clone(), 171 + Arc::clone(&self.is_enforced), 165 172 ) { 166 173 Ok(backend) => { 167 174 self.backend = Box::new(backend);
+8 -8
src/overlay/multi_slint.rs
··· 1 + use std::sync::atomic::{AtomicBool, Ordering}; 1 2 use std::sync::{Arc, Mutex}; 2 3 use std::time::Duration; 3 4 ··· 10 11 use crate::overlay::OverlayBackend; 11 12 use crate::overlay::fmt_dur; 12 13 use crate::overlay::monitors::MonitorInfo; 13 - use crate::timer::{active_profile, BreakMode, ScheduledBreak, TimerCommand}; 14 + use crate::timer::{ScheduledBreak, TimerCommand}; 14 15 15 16 struct WindowEntry { 16 17 window: OverlayWindow, ··· 28 29 monitors: &[MonitorInfo], 29 30 cmd_tx: tokio::sync::mpsc::UnboundedSender<TimerCommand>, 30 31 cfg_arc: Arc<Mutex<AppConfig>>, 32 + is_enforced: Arc<AtomicBool>, 31 33 ) -> anyhow::Result<Self> { 32 34 let mut entries = Vec::new(); 33 35 ··· 51 53 }; 52 54 let w = OverlayWindow::new()?; 53 55 w.set_is_dark(is_dark); 54 - wire_callbacks(&w, cmd_tx.clone(), cfg_arc.clone()); 56 + wire_callbacks(&w, cmd_tx.clone(), cfg_arc.clone(), Arc::clone(&is_enforced)); 55 57 w.hide().unwrap_or_default(); 56 58 entries.push(WindowEntry { 57 59 window: w, ··· 223 225 w: &OverlayWindow, 224 226 cmd_tx: tokio::sync::mpsc::UnboundedSender<TimerCommand>, 225 227 cfg_arc: Arc<Mutex<AppConfig>>, 228 + is_enforced: Arc<AtomicBool>, 226 229 ) { 227 230 // Snooze 228 231 { ··· 236 239 // in reminder mode dismiss the break immediately. 237 240 { 238 241 let tx = cmd_tx.clone(); 239 - let cfg = cfg_arc.clone(); 242 + let enforced = Arc::clone(&is_enforced); 240 243 let win = w.clone_strong(); 241 244 w.on_unlock_clicked(move || { 242 - let enforced = active_profile(&cfg.lock().unwrap()).mode == BreakMode::Enforced; 243 - if enforced { 245 + if enforced.load(Ordering::Relaxed) { 244 246 win.set_unlock_input_visible(true); 245 247 win.set_unlock_error("".into()); 246 248 } else { ··· 268 270 269 271 // Block OS close (Alt+F4) in enforced mode on every window. 270 272 { 271 - let cfg = cfg_arc.clone(); 272 273 w.window().on_close_requested(move || { 273 - let enforced = active_profile(&cfg.lock().unwrap()).mode == BreakMode::Enforced; 274 - if enforced { 274 + if is_enforced.load(Ordering::Relaxed) { 275 275 slint::CloseRequestResponse::KeepWindowShown 276 276 } else { 277 277 slint::CloseRequestResponse::HideWindow