Start handling command line parameters

This commit is contained in:
Savanni D'Gerinel 2023-04-10 10:46:35 -04:00
parent 8f4a8b77bc
commit 52ac235f49
1 changed files with 53 additions and 15 deletions

View File

@ -554,17 +554,58 @@ impl SlashMeter {
fn main() {
let app = gtk::Application::builder()
.application_id("com.luminescent-dreams.cyberpunk-splash")
.flags(gio::ApplicationFlags::HANDLES_OPEN)
.build();
app.add_main_option(
"title",
glib::char::Char::from(b't'),
glib::OptionFlags::IN_MAIN,
glib::OptionArg::String,
"",
None,
);
app.add_main_option(
"countdown",
glib::char::Char::from(b'c'),
glib::OptionFlags::IN_MAIN,
glib::OptionArg::String,
"",
None,
);
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| {
println!("connect_command_line");
1
});
app.connect_handle_local_options({
let title = title.clone();
move |_, options| {
println!("connect_handle_local_options");
*title.write().unwrap() = options.lookup::<String>("title").unwrap().unwrap();
-1
}
});
app.connect_open(move |app, files, args| {
println!("called open");
println!("files: {}", files.len());
println!("args: {}", args);
app.activate();
});
app.connect_activate(move |app| {
let (gtk_tx, gtk_rx) =
gtk::glib::MainContext::channel::<State>(gtk::glib::PRIORITY_DEFAULT);
let window = gtk::ApplicationWindow::new(app);
window.present();
let state = State::new(Duration::from_secs(5 * 60));
let splash = Splash::new("GTK Kifu".to_owned(), state.clone());
let state = Arc::new(RwLock::new(state));
let splash = Splash::new(title.read().unwrap().clone(), state.read().unwrap().clone());
window.set_child(Some(&splash));
@ -591,23 +632,20 @@ fn main() {
window.add_controller(keyboard_events);
gtk_rx.attach(None, move |state| {
/*
match event {
Event::Frames(frames) => splash.tick(frames),
Event::Time(time) => splash.set_time(time),
};
*/
splash.set_state(state);
Continue(true)
});
std::thread::spawn(move || {
std::thread::spawn({
let state = state.clone();
move || {
state.write().unwrap().start();
loop {
std::thread::sleep(Duration::from_millis(1000 / 60));
state.write().unwrap().run(Instant::now());
let _ = gtk_tx.send(state.read().unwrap().clone());
}
}
});
});