diff --git a/Cargo.lock b/Cargo.lock index ca7982e..f407f28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -925,6 +925,7 @@ dependencies = [ name = "cyberpunk-splash" version = "0.1.0" dependencies = [ + "async-std", "cairo-rs", "cyberpunk", "gio", diff --git a/cyberpunk-splash/Cargo.toml b/cyberpunk-splash/Cargo.toml index ffe5852..8874a83 100644 --- a/cyberpunk-splash/Cargo.toml +++ b/cyberpunk-splash/Cargo.toml @@ -7,6 +7,7 @@ license = "GPL-3.0-only" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +async-std = "1.13.0" cairo-rs = { version = "0.18" } cyberpunk = { path = "../cyberpunk" } gio = { version = "0.18" } diff --git a/cyberpunk-splash/src/main.rs b/cyberpunk-splash/src/main.rs index aae1235..4bd673f 100644 --- a/cyberpunk-splash/src/main.rs +++ b/cyberpunk-splash/src/main.rs @@ -497,8 +497,7 @@ fn main() { }); app.connect_activate(move |app| { - let (gtk_tx, gtk_rx) = - gtk::glib::MainContext::channel::(gtk::glib::Priority::DEFAULT); + let (gtk_tx, gtk_rx) = async_std::channel::unbounded(); let window = gtk::ApplicationWindow::new(app); window.present(); @@ -529,19 +528,25 @@ fn main() { }); window.add_controller(keyboard_events); - gtk_rx.attach(None, move |state| { - splash.set_state(state); - glib::ControlFlow::Continue + glib::spawn_future_local({ + let splash = splash.clone(); + async move { + while let Ok(state) = gtk_rx.recv().await { + println!("received state"); + splash.set_state(state); + } + } }); - std::thread::spawn({ + glib::spawn_future_local({ let state = state.clone(); - move || { + async move { state.write().unwrap().start(); loop { - std::thread::sleep(Duration::from_millis(1000 / 60)); + async_std::task::sleep(Duration::from_millis(1000 / 60)).await; state.write().unwrap().run(Instant::now()); - let _ = gtk_tx.send(*state.read().unwrap()); + println!("state: {:?}", state.read().unwrap()); + let _ = gtk_tx.send(*state.read().unwrap()).await; } } });