Switch cyberpunk-splash from deprecated glib channels
This commit is contained in:
parent
f9e4dcd68a
commit
da5144caea
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -925,6 +925,7 @@ dependencies = [
|
|||||||
name = "cyberpunk-splash"
|
name = "cyberpunk-splash"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"async-std",
|
||||||
"cairo-rs",
|
"cairo-rs",
|
||||||
"cyberpunk",
|
"cyberpunk",
|
||||||
"gio",
|
"gio",
|
||||||
|
@ -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
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
async-std = "1.13.0"
|
||||||
cairo-rs = { version = "0.18" }
|
cairo-rs = { version = "0.18" }
|
||||||
cyberpunk = { path = "../cyberpunk" }
|
cyberpunk = { path = "../cyberpunk" }
|
||||||
gio = { version = "0.18" }
|
gio = { version = "0.18" }
|
||||||
|
@ -497,8 +497,7 @@ fn main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.connect_activate(move |app| {
|
app.connect_activate(move |app| {
|
||||||
let (gtk_tx, gtk_rx) =
|
let (gtk_tx, gtk_rx) = async_std::channel::unbounded();
|
||||||
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();
|
||||||
@ -529,19 +528,25 @@ fn main() {
|
|||||||
});
|
});
|
||||||
window.add_controller(keyboard_events);
|
window.add_controller(keyboard_events);
|
||||||
|
|
||||||
gtk_rx.attach(None, move |state| {
|
glib::spawn_future_local({
|
||||||
splash.set_state(state);
|
let splash = splash.clone();
|
||||||
glib::ControlFlow::Continue
|
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();
|
let state = state.clone();
|
||||||
move || {
|
async move {
|
||||||
state.write().unwrap().start();
|
state.write().unwrap().start();
|
||||||
loop {
|
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());
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user