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: separates out timer types from mod

+83 -92
+3 -92
src/timer/mod.rs
··· 1 1 pub mod profile; 2 2 pub mod scheduler; 3 + pub mod types; 3 4 4 5 pub use profile::{active_profile, BreakMode, Profile}; 5 6 pub use scheduler::{LevelBreakStatus, LongBreakStatus, ScheduledBreak, Scheduler}; 7 + pub use types::{TimerCommand, TimerEvent}; 6 8 7 9 use std::sync::mpsc as std_mpsc; 8 10 use std::time::{Duration, Instant}; ··· 10 12 use tokio::time::interval; 11 13 12 14 use crate::config::AppConfig; 15 + use types::TimerState; 13 16 14 17 const TICK_INTERVAL: Duration = Duration::from_secs(1); 15 - 16 - // Commands sent to the timer task from the UI/tray. 17 - #[derive(Debug)] 18 - pub enum TimerCommand { 19 - // Pause the timer for the given duration. 20 - PauseFor(Duration), 21 - // Resume from manual pause early. 22 - Resume, 23 - // Advance to the next scheduled break immediately. 24 - SkipToNextBreak, 25 - // Called when a break overlay is dismissed (break finished or snoozed). 26 - BreakEnded { snoozed: bool }, 27 - // Called when idle is detected. 28 - IdleDetected { duration: Duration }, 29 - // Reload profile (after settings change). 30 - SetProfile(Profile), 31 - // Quit. 32 - Shutdown, 33 - } 34 - 35 - // Events sent from the timer task to the UI. 36 - #[derive(Debug, Clone)] 37 - pub enum TimerEvent { 38 - // A break is starting; show the overlay. 39 - BreakStarting(ScheduledBreak), 40 - // Snooze period starting; overlay hides temporarily. 41 - SnoozePeriodStarting { 42 - remaining_secs: u64, 43 - level_break_statuses: Vec<LevelBreakStatus>, 44 - long_break_status: Option<LongBreakStatus>, 45 - }, 46 - // Work phase: tick with current countdown to next break. 47 - WorkTick { 48 - secs_until_break: u64, 49 - level_break_statuses: Vec<LevelBreakStatus>, 50 - long_break_status: Option<LongBreakStatus>, 51 - }, 52 - // Timer is paused (manual or idle). 53 - Paused { 54 - remaining_secs: Option<u64>, 55 - }, 56 - // Timer resumed. 57 - Resumed { 58 - secs_until_break: u64, 59 - level_break_statuses: Vec<LevelBreakStatus>, 60 - long_break_status: Option<LongBreakStatus>, 61 - }, 62 - } 63 - 64 - #[derive(Debug, Clone)] 65 - enum TimerState { 66 - Working, 67 - // `fired_index` is the scheduler level that triggered this break, so 68 - // record_break_completed knows which counter to reset. 69 - Breaking { 70 - snooze_used: bool, 71 - is_long: bool, 72 - fired_index: usize, 73 - }, 74 - Snoozed { 75 - until: Instant, 76 - }, 77 - ManualPause { 78 - until: Option<Instant>, 79 - }, 80 - IdlePaused, 81 - } 82 - 83 - // Manual PartialEq — Instant does not implement PartialEq. 84 - impl PartialEq for TimerState { 85 - fn eq(&self, other: &Self) -> bool { 86 - match (self, other) { 87 - (Self::Working, Self::Working) => true, 88 - (Self::IdlePaused, Self::IdlePaused) => true, 89 - ( 90 - Self::Breaking { 91 - snooze_used: a, 92 - is_long: b, 93 - fired_index: c, 94 - }, 95 - Self::Breaking { 96 - snooze_used: d, 97 - is_long: e, 98 - fired_index: f, 99 - }, 100 - ) => a == d && b == e && c == f, 101 - (Self::Snoozed { .. }, Self::Snoozed { .. }) => true, 102 - (Self::ManualPause { until: a }, Self::ManualPause { until: b }) => a == b, 103 - _ => false, 104 - } 105 - } 106 - } 107 18 108 19 pub struct TimerTask { 109 20 scheduler: Scheduler,
+80
src/timer/types.rs
··· 1 + use std::time::{Duration, Instant}; 2 + 3 + use crate::timer::profile::Profile; 4 + use crate::timer::scheduler::{LevelBreakStatus, LongBreakStatus, ScheduledBreak}; 5 + 6 + #[derive(Debug)] 7 + pub enum TimerCommand { 8 + PauseFor(Duration), 9 + Resume, 10 + SkipToNextBreak, 11 + BreakEnded { snoozed: bool }, 12 + IdleDetected { duration: Duration }, 13 + SetProfile(Profile), 14 + Shutdown, 15 + } 16 + 17 + #[derive(Debug, Clone)] 18 + pub enum TimerEvent { 19 + BreakStarting(ScheduledBreak), 20 + SnoozePeriodStarting { 21 + remaining_secs: u64, 22 + level_break_statuses: Vec<LevelBreakStatus>, 23 + long_break_status: Option<LongBreakStatus>, 24 + }, 25 + WorkTick { 26 + secs_until_break: u64, 27 + level_break_statuses: Vec<LevelBreakStatus>, 28 + long_break_status: Option<LongBreakStatus>, 29 + }, 30 + Paused { 31 + remaining_secs: Option<u64>, 32 + }, 33 + Resumed { 34 + secs_until_break: u64, 35 + level_break_statuses: Vec<LevelBreakStatus>, 36 + long_break_status: Option<LongBreakStatus>, 37 + }, 38 + } 39 + 40 + #[derive(Debug, Clone)] 41 + pub(super) enum TimerState { 42 + Working, 43 + Breaking { 44 + snooze_used: bool, 45 + is_long: bool, 46 + fired_index: usize, 47 + }, 48 + Snoozed { 49 + until: Instant, 50 + }, 51 + ManualPause { 52 + until: Option<Instant>, 53 + }, 54 + IdlePaused, 55 + } 56 + 57 + // Manual PartialEq — Instant does not implement PartialEq. 58 + impl PartialEq for TimerState { 59 + fn eq(&self, other: &Self) -> bool { 60 + match (self, other) { 61 + (Self::Working, Self::Working) => true, 62 + (Self::IdlePaused, Self::IdlePaused) => true, 63 + ( 64 + Self::Breaking { 65 + snooze_used: a, 66 + is_long: b, 67 + fired_index: c, 68 + }, 69 + Self::Breaking { 70 + snooze_used: d, 71 + is_long: e, 72 + fired_index: f, 73 + }, 74 + ) => a == d && b == e && c == f, 75 + (Self::Snoozed { .. }, Self::Snoozed { .. }) => true, 76 + (Self::ManualPause { until: a }, Self::ManualPause { until: b }) => a == b, 77 + _ => false, 78 + } 79 + } 80 + }