"timer can run" button now unpauses when timer is paused

This commit is contained in:
Nickiel12 2022-06-29 20:33:31 -07:00
parent 9a867e0735
commit db866b4b8d

View file

@ -70,6 +70,9 @@ impl MessageHandler for StreamState {
} }
}, },
StateUpdate::TimerCanRun(value) => { StateUpdate::TimerCanRun(value) => {
if self.timer_paused_length.is_some(){
return (None, Some(vec![StateUpdate::PauseTimer(false)]));
}
self.timer_can_run = value; self.timer_can_run = value;
self.timer_start = SystemTime::now(); self.timer_start = SystemTime::now();
if value { if value {
@ -79,7 +82,7 @@ impl MessageHandler for StreamState {
} else { } else {
return (Some(update), None); return (Some(update), None);
} }
} },
StateUpdate::PauseTimer(value) => {return self.pause_timer(value)}, StateUpdate::PauseTimer(value) => {return self.pause_timer(value)},
StateUpdate::TimerLength(value) => {self.timer_length = value; return (Some(update), None)}, StateUpdate::TimerLength(value) => {self.timer_length = value; return (Some(update), None)},
StateUpdate::TimerText(value) => {self.timer_text = value.clone(); return (Some(StateUpdate::TimerText(value)), None)}, StateUpdate::TimerText(value) => {self.timer_text = value.clone(); return (Some(StateUpdate::TimerText(value)), None)},
@ -152,9 +155,9 @@ impl MessageHandler for StreamState {
match self.timer_start.elapsed() { match self.timer_start.elapsed() {
Err(_) => {time_left = 0}, Err(_) => {time_left = 0},
Ok(change) => { Ok(change) => {
// take the duration, multiply it by 10 to save the last decimal, // take the duration left, multiply it by 10 to save the last decimal,
// then drop the rest of the digits with .round() // then drop the rest of the digits with .round()
time_left = (self.timer_length - (change.as_secs_f32() * 10.0).round()) as u16; time_left = ((self.timer_length - change.as_secs_f32()) * 10.0).round() as u16;
} }
} }
self.timer_paused_length = Some(time_left); self.timer_paused_length = Some(time_left);