From 01d92aaede032f4fe46a635a09722a2710f4b911 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Thu, 21 May 2020 23:59:38 -0500 Subject: [PATCH] Handle missing audio file and, fix logic error --- src/lib.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4c85b14..370fed7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,10 +24,11 @@ pub mod pomodoro { } pub fn play(&self) { - let file = File::open(self.path).unwrap(); - let source = Decoder::new(BufReader::new(file)).unwrap(); - - rodio::play_raw(self.device, source.convert_samples()); + if self.path.exists() { + let file = File::open(self.path).unwrap(); + let source = Decoder::new(BufReader::new(file)).unwrap(); + rodio::play_raw(self.device, source.convert_samples()); + } } } @@ -180,7 +181,7 @@ pub mod pomodoro { match elapsed { Some(duration) => { - let remaining = (status.length.as_secs() * 60) - duration.as_secs(); + let remaining = status.length.as_secs() - duration.as_secs(); let seconds = remaining; let hours = seconds / 3600;