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-22 02:07:19 +00:00
|
|
|
|
2020-05-21 04:04:31 +00:00
|
|
|
fn main() {
|
2020-12-08 22:18:38 +00:00
|
|
|
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()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-31 03:15:51 +00:00
|
|
|
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() {
|
2020-12-14 03:44:56 +00:00
|
|
|
Some(alert) => domasi.start(Some(alert)).unwrap(),
|
|
|
|
None => domasi.start(None).unwrap(),
|
2020-08-31 05:18:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-08 22:18:38 +00:00
|
|
|
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
|
|
|
}
|