Skip to main content

zentime_rs_timer/pomodoro_timer/
on_end_handler.rs

1use std::rc::Rc;
2
3use crate::timer::TimerEndHandler;
4
5use super::state::PomodoroTimerState;
6
7/// Describes pomodoro timer kind
8#[derive(Debug, Copy, Clone, PartialEq, Eq)]
9pub enum TimerKind {
10    /// Always used when the current timer is not a break timer
11    Interval,
12
13    /// Only used for breaks
14    Break,
15}
16
17pub type OnTimerEnd = Rc<dyn Fn(PomodoroTimerState, Option<&str>, TimerKind)>;
18
19/// Handler which is passed to our timer implementation
20pub struct OnEndHandler {
21    pub on_timer_end: OnTimerEnd,
22    pub state: PomodoroTimerState,
23    pub notification: Option<&'static str>,
24    pub kind: TimerKind,
25}
26
27impl TimerEndHandler for OnEndHandler {
28    fn call(&mut self) {
29        (self.on_timer_end)(self.state, self.notification, self.kind);
30    }
31}