Compare commits

..

No commits in common. "d86d10428b04b160dac08f839d96732e3be0ef30" and "f2cca31310494e0eaf666376696c5480308bf892" have entirely different histories.

2 changed files with 8 additions and 42 deletions

View File

@ -11,12 +11,11 @@ pub enum Request {
PlayingField,
}
#[derive(Debug)]
pub enum Response {
PlayingFieldView(PlayingFieldView),
}
fn dispatch(state: Arc<RwLock<AppState>>, request: Request) -> Response {
fn disptach(state: Arc<RwLock<AppState>>, request: Request) -> Response {
match request {
Request::PlayingField => Response::PlayingFieldView(playing_field()),
}
@ -46,11 +45,8 @@ impl CoreApp {
)
}
pub async fn run(&mut self) {
loop {
let msg = self.request_rx.recv().await.unwrap();
let resp = dispatch(self.state.clone(), msg);
self.response_tx.send(resp).await.unwrap();
}
pub async fn run(&self) {
thread::sleep(Duration::from_secs(5));
unimplemented!()
}
}

View File

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