Compare commits
No commits in common. "d86d10428b04b160dac08f839d96732e3be0ef30" and "f2cca31310494e0eaf666376696c5480308bf892" have entirely different histories.
d86d10428b
...
f2cca31310
|
@ -11,12 +11,11 @@ pub enum Request {
|
||||||
PlayingField,
|
PlayingField,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum Response {
|
pub enum Response {
|
||||||
PlayingFieldView(PlayingFieldView),
|
PlayingFieldView(PlayingFieldView),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch(state: Arc<RwLock<AppState>>, request: Request) -> Response {
|
fn disptach(state: Arc<RwLock<AppState>>, request: Request) -> Response {
|
||||||
match request {
|
match request {
|
||||||
Request::PlayingField => Response::PlayingFieldView(playing_field()),
|
Request::PlayingField => Response::PlayingFieldView(playing_field()),
|
||||||
}
|
}
|
||||||
|
@ -46,11 +45,8 @@ impl CoreApp {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run(&mut self) {
|
pub async fn run(&self) {
|
||||||
loop {
|
thread::sleep(Duration::from_secs(5));
|
||||||
let msg = self.request_rx.recv().await.unwrap();
|
unimplemented!()
|
||||||
let resp = dispatch(self.state.clone(), msg);
|
|
||||||
self.response_tx.send(resp).await.unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use kifu_core::{CoreApp, Request, Response};
|
use kifu_core::CoreApp;
|
||||||
use std::{
|
use tokio::runtime::Runtime;
|
||||||
sync::{Arc, Mutex},
|
|
||||||
time::Duration,
|
|
||||||
};
|
|
||||||
use tokio::sync::mpsc::{Receiver, Sender};
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn 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 {
|
let core_handle = tokio::spawn(async move {
|
||||||
core.run().await;
|
core.run().await;
|
||||||
});
|
});
|
||||||
|
@ -18,25 +14,9 @@ async fn main() {
|
||||||
.application_id("com.luminescent-dreams.kifu-gtk")
|
.application_id("com.luminescent-dreams.kifu-gtk")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let _ = tokio::spawn({
|
app.connect_activate(|app| {
|
||||||
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");
|
||||||
|
@ -46,13 +26,3 @@ 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