Try setting up the GTK loop

This commit is contained in:
Savanni D'Gerinel 2023-03-20 09:43:56 -04:00
parent 9b58770070
commit d86d10428b
1 changed files with 34 additions and 4 deletions

View File

@ -1,10 +1,14 @@
use gtk::prelude::*;
use kifu_core::CoreApp;
use tokio::runtime::Runtime;
use kifu_core::{CoreApp, Request, Response};
use std::{
sync::{Arc, Mutex},
time::Duration,
};
use tokio::sync::mpsc::{Receiver, Sender};
#[tokio::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 {
core.run().await;
});
@ -14,9 +18,25 @@ async fn main() {
.application_id("com.luminescent-dreams.kifu-gtk")
.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);
window.present();
gtk_rx.attach(None, |message| {
println!("message: {:?}", message);
Continue(true)
});
});
println!("running the gtk loop");
@ -26,3 +46,13 @@ async fn main() {
core_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 => (),
}
}
}