feat(state): add paused to timer state

This commit is contained in:
Dmitriy Pleshevskiy 2022-02-18 00:12:20 +03:00
parent ef1e00dff8
commit 17302d71a5
2 changed files with 18 additions and 11 deletions

View File

@ -22,14 +22,7 @@ fn main() {
.ok();
});
let initial_state = state::App {
paused: false,
micro_break: state::BreakTimer::new(),
rest_break: state::BreakTimer::new(),
notifier: state::Timer::new(),
sound_sender: std::rc::Rc::new(tx.clone()),
};
let initial_state = state::App::new(tx, true);
AppLauncher::with_window(win::status::create(initial_state.sound_sender.clone()))
.delegate(Delegate::default())
.configure_env(env::configure)

View File

@ -13,15 +13,27 @@ pub struct App {
pub notifier: Timer,
}
impl App {
pub fn new(sound_sender: sound::Sender, paused: bool) -> Self {
Self {
paused,
micro_break: BreakTimer::new(paused),
rest_break: BreakTimer::new(paused),
notifier: Timer::new(false),
sound_sender: Rc::new(sound_sender),
}
}
}
#[derive(Clone, Data, Lens)]
pub struct BreakTimer {
pub work_timer: Timer,
}
impl BreakTimer {
pub fn new() -> Self {
pub fn new(paused: bool) -> Self {
Self {
work_timer: Timer::new(),
work_timer: Timer::new(paused),
}
}
}
@ -30,13 +42,15 @@ impl BreakTimer {
pub struct Timer {
pub progress: f64,
pub time: String,
pub paused: bool,
}
impl Timer {
pub fn new() -> Self {
pub fn new(paused: bool) -> Self {
Self {
progress: Default::default(),
time: Default::default(),
paused,
}
}