domasi/src/main.rs

42 lines
983 B
Rust
Raw Normal View History

2020-08-31 05:18:39 +00:00
use directories::ProjectDirs;
use domasi::Alert;
2020-08-31 01:22:27 +00:00
use domasi::Pomodoro;
2020-08-31 05:18:39 +00:00
use std::fs;
use std::path::PathBuf;
2020-05-21 04:04:31 +00:00
fn main() {
let mut domasi: Pomodoro = Default::default();
2020-05-21 06:03:38 +00:00
2020-08-31 05:18:39 +00:00
match get_alert() {
Some(alert) => domasi.start_with_alert(alert),
None => domasi.start(),
}
}
fn get_alert() -> Option<Alert> {
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<PathBuf> {
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
2020-05-25 06:51:07 +00:00
}