Switch cyberpunk-splash from deprecated glib channels

This commit is contained in:
Savanni D'Gerinel 2025-01-19 13:18:31 -05:00
parent f9e4dcd68a
commit da5144caea
3 changed files with 16 additions and 9 deletions

1
Cargo.lock generated
View File

@ -925,6 +925,7 @@ dependencies = [
name = "cyberpunk-splash"
version = "0.1.0"
dependencies = [
"async-std",
"cairo-rs",
"cyberpunk",
"gio",

View File

@ -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" }

View File

@ -497,8 +497,7 @@ fn main() {
});
app.connect_activate(move |app| {
let (gtk_tx, gtk_rx) =
gtk::glib::MainContext::channel::<State>(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| {
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);
glib::ControlFlow::Continue
}
}
});
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;
}
}
});