Parse the countdown parameter

This commit is contained in:
Savanni D'Gerinel 2023-04-13 18:56:42 -04:00 committed by Gitea
parent 70b34f41b5
commit ad6b006e1c
1 changed files with 30 additions and 1 deletions

View File

@ -577,15 +577,44 @@ fn main() {
let state = Arc::new(RwLock::new(State::new(Duration::from_secs(5 * 60)))); let state = Arc::new(RwLock::new(State::new(Duration::from_secs(5 * 60))));
let title = Arc::new(RwLock::new("".to_owned())); let title = Arc::new(RwLock::new("".to_owned()));
app.connect_command_line(|_, args| { app.connect_command_line(|_, _args| {
println!("connect_command_line"); println!("connect_command_line");
1 1
}); });
app.connect_handle_local_options({ app.connect_handle_local_options({
let title = title.clone(); let title = title.clone();
let state = state.clone();
move |_, options| { move |_, options| {
println!("connect_handle_local_options"); println!("connect_handle_local_options");
*title.write().unwrap() = options.lookup::<String>("title").unwrap().unwrap(); *title.write().unwrap() = options.lookup::<String>("title").unwrap().unwrap();
let countdown = match options.lookup::<String>("countdown") {
Ok(Some(countdown_str)) => {
let parts = countdown_str.split(':').collect::<Vec<&str>>();
let duration = match parts.len() {
2 => {
let minutes = parts[0].parse::<u64>().unwrap();
let seconds = parts[1].parse::<u64>().unwrap();
Duration::from_secs(minutes * 60 + seconds)
}
1 => {
let seconds = parts[1].parse::<u64>().unwrap();
Duration::from_secs(seconds)
}
_ => Duration::from_secs(300),
};
duration
}
_ => Duration::from_secs(300),
};
match *state.write().unwrap() {
State::Running {
ref mut deadline, ..
} => *deadline = Instant::now() + countdown,
State::Paused {
ref mut time_remaining,
..
} => *time_remaining = countdown,
}
-1 -1
} }
}); });