2022-06-03 02:03:37 +02:00
|
|
|
mod app;
|
2022-06-05 20:05:39 +02:00
|
|
|
mod util;
|
2022-06-03 02:03:37 +02:00
|
|
|
|
2022-06-06 04:42:06 +02:00
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
use tokio::time::{sleep, Duration};
|
2022-06-05 20:05:39 +02:00
|
|
|
use crate::util::worker::{BackgroundWorker, NativeBackgroundWorker};
|
2022-06-06 04:42:06 +02:00
|
|
|
use crate::app::{App, data::store::{SQLiteDataStore, DataStorage}};
|
2022-06-05 20:05:39 +02:00
|
|
|
|
2022-06-03 02:03:37 +02:00
|
|
|
// When compiling natively:
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
2022-06-06 04:42:06 +02:00
|
|
|
fn main() -> ! {
|
2022-06-03 02:03:37 +02:00
|
|
|
let native_options = eframe::NativeOptions::default();
|
2022-06-06 04:42:06 +02:00
|
|
|
|
|
|
|
let mut store_path = dirs::data_dir().unwrap_or(std::path::PathBuf::from(".")); // TODO get cwd more consistently?
|
|
|
|
store_path.push("dashboard.db");
|
|
|
|
|
|
|
|
println!("{}", store_path.as_path().to_str().unwrap());
|
2022-06-03 02:03:37 +02:00
|
|
|
|
2022-06-06 04:42:06 +02:00
|
|
|
let store = Arc::new(
|
|
|
|
SQLiteDataStore::new(store_path)
|
|
|
|
.unwrap()
|
|
|
|
);
|
2022-06-05 20:05:39 +02:00
|
|
|
|
|
|
|
eframe::run_native( // TODO replace this with a loop that ends so we can cleanly exit the background worker
|
2022-06-06 04:42:06 +02:00
|
|
|
"dashboard",
|
2022-06-03 02:03:37 +02:00
|
|
|
native_options,
|
2022-06-06 04:42:06 +02:00
|
|
|
Box::new(move |cc| {
|
|
|
|
let worker = NativeBackgroundWorker::start();
|
|
|
|
let ctx = cc.egui_ctx.clone();
|
|
|
|
worker.task(async move {
|
|
|
|
loop {
|
|
|
|
sleep(Duration::from_secs(1)).await;
|
|
|
|
ctx.request_repaint();
|
|
|
|
// tokio::spawn(async move {store2.fetch_all().await});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Box::new(App::new(cc, store))
|
|
|
|
}),
|
2022-06-03 02:03:37 +02:00
|
|
|
);
|
2022-06-05 20:05:39 +02:00
|
|
|
|
|
|
|
// worker.stop();
|
2022-06-03 02:03:37 +02:00
|
|
|
}
|