use directories::ProjectDirs; use domasi::Alert; use domasi::Pomodoro; use std::fs; use std::path::PathBuf; fn main() { let mut domasi: Pomodoro = Default::default(); match get_alert() { Some(alert) => domasi.start_with_alert(alert), None => domasi.start(), } } fn get_alert() -> Option { let alert_dir = ProjectDirs::from("moe", "paoda", "domasi") .unwrap() .data_dir() .to_path_buf() .join("alert"); let file = find_alert_file(alert_dir)?; Some(Alert::new(file)) } fn find_alert_file(path: PathBuf) -> Option { let items = fs::read_dir(path).ok()?; for entry_result in items { if let Ok(entry) = entry_result { if let Some(ext) = entry.path().extension() { if let Some("mp3") | Some("wav") | Some("ogg") | Some("flac") = ext.to_str() { return Some(entry.path()); } } } } None }