#![warn(missing_docs)]
#![doc = include_str!("../README.md")]
use std::path::PathBuf;
use crate::pomodoro_options::{
read_options_from_json, write_default_options_to_json_next_to_executable,
};
use crate::pomodoro_options::{PomodoroOptions, PomodoroOptionsError};
use crate::cli_utilities::start_pomodoro;
mod input_handler;
mod message_creator;
mod pomo_info;
mod pomodoro_options;
mod timer;
mod cli_utilities;
mod end_events;
fn main() {
let logging_config_file = PathBuf::from("pomodoro_logging.yaml");
if logging_config_file.is_file() {
log4rs::init_file(logging_config_file, Default::default()).unwrap();
}
let data = read_options_from_json(None);
let json_data = match data {
Ok(json_data) => json_data,
Err(e) => {
match e.downcast_ref::<PomodoroOptionsError>() {
Some(PomodoroOptionsError::OptionFileNotFound(_)) => {
write_default_options_to_json_next_to_executable()
.expect("Failed to write default options to JSON file.");
println!(
"Apparently, you are using the Locking Pomodoro Timer for the first time (at least in this folder). \
A file named 'pomodoro_options.json' will be created next to the executable. \
You can change the settings in this file. \
To find more information about the Locking Pomodoro Timer, visit the GitHub page: \
https://github.com/davidzanger/Locking-Pomodoro-Timer.git"
);
PomodoroOptions::default()
}
None => {
eprintln!("Error: {:#}", e);
eprintln!("Using default options.");
PomodoroOptions::default()
}
}
}
};
start_pomodoro(&json_data)
}