domasi/src/main.rs

65 lines
1.5 KiB
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 args = std::env::args_os();
if let Some(os_string) = args.nth(1) {
match os_string.to_str() {
Some("-C") | Some("--create-config") => {
let _ = create_alert_directory();
}
None => {}
arg => println!("Unsupported Argument: {}", arg.unwrap()),
}
}
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 create_alert_directory() -> std::io::Result<()> {
let alert_dir = ProjectDirs::from("moe", "paoda", "domasi")
.unwrap()
.data_dir()
.to_path_buf()
.join("alert");
fs::create_dir_all(alert_dir)?;
Ok(())
}
2020-08-31 05:18:39 +00:00
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
}