2023-03-23 03:11:56 +00:00
|
|
|
pub mod ui;
|
2023-05-13 18:02:24 +00:00
|
|
|
use kifu_core::{CoreApp, CoreRequest, CoreResponse};
|
2023-04-07 01:52:39 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
use tokio::runtime::Runtime;
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct CoreApi {
|
2023-05-13 18:02:24 +00:00
|
|
|
pub gtk_tx: gtk::glib::Sender<CoreResponse>,
|
2023-04-07 01:52:39 +00:00
|
|
|
pub rt: Arc<Runtime>,
|
|
|
|
pub core: CoreApp,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CoreApi {
|
2023-05-13 18:02:24 +00:00
|
|
|
pub fn dispatch(&self, request: CoreRequest) {
|
2023-04-07 01:52:39 +00:00
|
|
|
self.rt.spawn({
|
|
|
|
let gtk_tx = self.gtk_tx.clone();
|
|
|
|
let core = self.core.clone();
|
|
|
|
async move { gtk_tx.send(core.dispatch(request).await) }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2023-06-15 03:47:12 +00:00
|
|
|
|
|
|
|
pub fn perftrace<F, A>(trace_name: &str, f: F) -> A
|
|
|
|
where
|
|
|
|
F: FnOnce() -> A,
|
|
|
|
{
|
|
|
|
let start = std::time::Instant::now();
|
|
|
|
let result = f();
|
|
|
|
let end = std::time::Instant::now();
|
|
|
|
println!("[Trace: {}] {:?}", trace_name, end - start);
|
|
|
|
return result;
|
|
|
|
}
|