Handle missing audio file and, fix logic error
This commit is contained in:
		
							
								
								
									
										11
									
								
								src/lib.rs
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/lib.rs
									
									
									
									
									
								
							@@ -24,10 +24,11 @@ pub mod pomodoro {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        pub fn play(&self) {
 | 
					        pub fn play(&self) {
 | 
				
			||||||
            let file = File::open(self.path).unwrap();
 | 
					            if self.path.exists() {
 | 
				
			||||||
            let source = Decoder::new(BufReader::new(file)).unwrap();
 | 
					                let file = File::open(self.path).unwrap();
 | 
				
			||||||
 | 
					                let source = Decoder::new(BufReader::new(file)).unwrap();
 | 
				
			||||||
            rodio::play_raw(self.device, source.convert_samples());
 | 
					                rodio::play_raw(self.device, source.convert_samples());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -180,7 +181,7 @@ pub mod pomodoro {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            match elapsed {
 | 
					            match elapsed {
 | 
				
			||||||
                Some(duration) => {
 | 
					                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 seconds = remaining;
 | 
				
			||||||
                    let hours = seconds / 3600;
 | 
					                    let hours = seconds / 3600;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user