Start handling command line parameters
This commit is contained in:
parent
78acebbf06
commit
70b34f41b5
|
@ -554,17 +554,58 @@ impl SlashMeter {
|
||||||
fn main() {
|
fn main() {
|
||||||
let app = gtk::Application::builder()
|
let app = gtk::Application::builder()
|
||||||
.application_id("com.luminescent-dreams.cyberpunk-splash")
|
.application_id("com.luminescent-dreams.cyberpunk-splash")
|
||||||
|
.flags(gio::ApplicationFlags::HANDLES_OPEN)
|
||||||
.build();
|
.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| {
|
app.connect_activate(move |app| {
|
||||||
let (gtk_tx, gtk_rx) =
|
let (gtk_tx, gtk_rx) =
|
||||||
gtk::glib::MainContext::channel::<State>(gtk::glib::PRIORITY_DEFAULT);
|
gtk::glib::MainContext::channel::<State>(gtk::glib::PRIORITY_DEFAULT);
|
||||||
|
|
||||||
let window = gtk::ApplicationWindow::new(app);
|
let window = gtk::ApplicationWindow::new(app);
|
||||||
window.present();
|
window.present();
|
||||||
|
|
||||||
let state = State::new(Duration::from_secs(5 * 60));
|
let splash = Splash::new(title.read().unwrap().clone(), state.read().unwrap().clone());
|
||||||
let splash = Splash::new("GTK Kifu".to_owned(), state.clone());
|
|
||||||
let state = Arc::new(RwLock::new(state));
|
|
||||||
|
|
||||||
window.set_child(Some(&splash));
|
window.set_child(Some(&splash));
|
||||||
|
|
||||||
|
@ -591,22 +632,19 @@ fn main() {
|
||||||
window.add_controller(keyboard_events);
|
window.add_controller(keyboard_events);
|
||||||
|
|
||||||
gtk_rx.attach(None, move |state| {
|
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);
|
splash.set_state(state);
|
||||||
Continue(true)
|
Continue(true)
|
||||||
});
|
});
|
||||||
|
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn({
|
||||||
state.write().unwrap().start();
|
let state = state.clone();
|
||||||
loop {
|
move || {
|
||||||
std::thread::sleep(Duration::from_millis(1000 / 60));
|
state.write().unwrap().start();
|
||||||
state.write().unwrap().run(Instant::now());
|
loop {
|
||||||
let _ = gtk_tx.send(state.read().unwrap().clone());
|
std::thread::sleep(Duration::from_millis(1000 / 60));
|
||||||
|
state.write().unwrap().run(Instant::now());
|
||||||
|
let _ = gtk_tx.send(state.read().unwrap().clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue