Create a cyberpunk-style splash screen with a title and a countdown #39

Merged
savanni merged 11 commits from cyberpunk-display into main 2023-04-13 23:14:29 +00:00
1 changed files with 30 additions and 1 deletions
Showing only changes of commit 11391aad68 - Show all commits

View File

@ -577,15 +577,44 @@ fn main() {
let state = Arc::new(RwLock::new(State::new(Duration::from_secs(5 * 60))));
let title = Arc::new(RwLock::new("".to_owned()));
app.connect_command_line(|_, args| {
app.connect_command_line(|_, _args| {
println!("connect_command_line");
1
});
app.connect_handle_local_options({
let title = title.clone();
let state = state.clone();
move |_, options| {
println!("connect_handle_local_options");
*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
}
});