Try setting up the GTK loop
This commit is contained in:
parent
9b58770070
commit
d86d10428b
|
@ -1,10 +1,14 @@
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use kifu_core::CoreApp;
|
use kifu_core::{CoreApp, Request, Response};
|
||||||
use tokio::runtime::Runtime;
|
use std::{
|
||||||
|
sync::{Arc, Mutex},
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
use tokio::sync::mpsc::{Receiver, Sender};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let (core, _request_tx, _response_rx) = CoreApp::new();
|
let (mut core, request_tx, response_rx) = CoreApp::new();
|
||||||
let core_handle = tokio::spawn(async move {
|
let core_handle = tokio::spawn(async move {
|
||||||
core.run().await;
|
core.run().await;
|
||||||
});
|
});
|
||||||
|
@ -14,9 +18,25 @@ async fn main() {
|
||||||
.application_id("com.luminescent-dreams.kifu-gtk")
|
.application_id("com.luminescent-dreams.kifu-gtk")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
app.connect_activate(|app| {
|
let _ = tokio::spawn({
|
||||||
|
let request_tx = request_tx.clone();
|
||||||
|
async move {
|
||||||
|
let _ = request_tx.send(Request::PlayingField).await;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.connect_activate(move |app| {
|
||||||
|
let (gtk_tx, gtk_rx) =
|
||||||
|
gtk::glib::MainContext::channel::<Response>(gtk::glib::PRIORITY_DEFAULT);
|
||||||
|
|
||||||
|
let _ = tokio::task::spawn(connector(gtk_tx, response_rx));
|
||||||
|
|
||||||
let window = gtk::ApplicationWindow::new(app);
|
let window = gtk::ApplicationWindow::new(app);
|
||||||
window.present();
|
window.present();
|
||||||
|
gtk_rx.attach(None, |message| {
|
||||||
|
println!("message: {:?}", message);
|
||||||
|
Continue(true)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
println!("running the gtk loop");
|
println!("running the gtk loop");
|
||||||
|
@ -26,3 +46,13 @@ async fn main() {
|
||||||
core_handle.await;
|
core_handle.await;
|
||||||
gtk_handle.await;
|
gtk_handle.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn connector(gtk_tx: gtk::glib::Sender<Response>, mut response_rx: Receiver<Response>) {
|
||||||
|
loop {
|
||||||
|
let msg = response_rx.recv().await;
|
||||||
|
match msg {
|
||||||
|
Some(msg) => gtk_tx.send(msg).unwrap(),
|
||||||
|
None => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue