diff --git a/.gitignore b/.gitignore index cdaaa5a..86d90d1 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk + +# These are build files generated by Trunk +dist/ diff --git a/Cargo.toml b/Cargo.toml index 867b2a6..2002d31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,18 +16,24 @@ dirs = "4" git-version = "0.3.5" chrono = "0.4" tracing = "0.1" # egui / eframe use tracing -tracing-subscriber = "0.3" serde = { version = "1", features = ["derive"] } serde_json = "1" csv = "1.1" jql = { version = "4", default-features = false } rfd = "0.9" -eframe = "0.19" +eframe = { version = "0.19", features = ["persistence"] } tokio = { version = "1", features = ["full"] } clap = { version = "4", features = ["derive"] } futures = "0.3" sea-orm = { version = "0.10", features = [ "runtime-tokio-rustls", "sqlx-sqlite", "macros" ] } reqwest = { version = "0.11", features = ["json"] } -[profile.dev.package."*"] -opt-level = 3 +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +tracing-subscriber = "0.3" + +[target.'cfg(target_arch = "wasm32")'.dependencies] +console_error_panic_hook = "0.1.6" +tracing-wasm = "0.2" + +# [profile.dev.package."*"] +# opt-level = 3 diff --git a/Trunk.toml b/Trunk.toml new file mode 100644 index 0000000..bd6c484 --- /dev/null +++ b/Trunk.toml @@ -0,0 +1,2 @@ +[build] +filehash = false diff --git a/assets/favicon.ico b/assets/favicon.ico new file mode 100755 index 0000000..61ad031 Binary files /dev/null and b/assets/favicon.ico differ diff --git a/assets/icon-1024.png b/assets/icon-1024.png new file mode 100644 index 0000000..1b5868a Binary files /dev/null and b/assets/icon-1024.png differ diff --git a/assets/icon-256.png b/assets/icon-256.png new file mode 100644 index 0000000..ae72287 Binary files /dev/null and b/assets/icon-256.png differ diff --git a/assets/icon_ios_touch_192.png b/assets/icon_ios_touch_192.png new file mode 100644 index 0000000..8472802 Binary files /dev/null and b/assets/icon_ios_touch_192.png differ diff --git a/assets/manifest.json b/assets/manifest.json new file mode 100644 index 0000000..2a137fb --- /dev/null +++ b/assets/manifest.json @@ -0,0 +1,28 @@ +{ + "name": "egui Template PWA", + "short_name": "egui-template-pwa", + "icons": [ + { + "src": "./icon-256.png", + "sizes": "256x256", + "type": "image/png" + }, + { + "src": "./maskable_icon_x512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "any maskable" + }, + { + "src": "./icon-1024.png", + "sizes": "1024x1024", + "type": "image/png" + } + ], + "lang": "en-US", + "id": "/index.html", + "start_url": "./index.html", + "display": "standalone", + "background_color": "white", + "theme_color": "white" +} diff --git a/assets/maskable_icon_x512.png b/assets/maskable_icon_x512.png new file mode 100644 index 0000000..db8df3e Binary files /dev/null and b/assets/maskable_icon_x512.png differ diff --git a/assets/sw.js b/assets/sw.js new file mode 100644 index 0000000..7ecd229 --- /dev/null +++ b/assets/sw.js @@ -0,0 +1,25 @@ +var cacheName = 'egui-template-pwa'; +var filesToCache = [ + './', + './index.html', + './eframe_template.js', + './eframe_template_bg.wasm', +]; + +/* Start the service worker and cache all of the app's content */ +self.addEventListener('install', function (e) { + e.waitUntil( + caches.open(cacheName).then(function (cache) { + return cache.addAll(filesToCache); + }) + ); +}); + +/* Serve cached content when offline */ +self.addEventListener('fetch', function (e) { + e.respondWith( + caches.match(e.request).then(function (response) { + return response || fetch(e.request); + }) + ); +}); diff --git a/index.html b/index.html new file mode 100644 index 0000000..872b4f4 --- /dev/null +++ b/index.html @@ -0,0 +1,140 @@ + + + + + + + + + + eframe template + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/gui/mod.rs b/src/gui/mod.rs index 72f76e7..1cb0217 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -5,7 +5,7 @@ pub mod metric; mod scaffold; use chrono::Utc; -use eframe::egui::{CentralPanel, Context, SidePanel, TopBottomPanel}; +use eframe::egui::{CentralPanel, Context, SidePanel, TopBottomPanel, Window}; use tokio::sync::watch; use crate::{data::entities, worker::visualizer::AppStateView}; @@ -35,6 +35,7 @@ pub struct App { edit: bool, sidebar: bool, padding: bool, + // windows: Vec>, } impl App { @@ -56,6 +57,7 @@ impl App { edit: false, sidebar: true, padding: false, + // windows: vec![], } } @@ -80,6 +82,8 @@ impl eframe::App for App { footer(ctx, ui, self.logger_view.clone(), self.db_path.clone(), self.view.points.borrow().len()); }); + let w = Window::new("a"); + // if let Some(index) = self.deleting_metric { // Window::new(format!("Delete Metric #{}?", index)) // .show(ctx, |ui| confirmation_popup_delete_metric(self, ui, index)); diff --git a/src/main.rs b/src/main.rs index 3eb0cc2..a435d1c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ use sea_orm::Database; use worker::visualizer::AppState; use worker::surveyor_loop; -use util::InternalLogger; +use util::{InternalLogger, InternalLoggerLayer}; use gui::{ // util::InternalLogger, App @@ -49,8 +49,27 @@ struct CliArgs { log_size: u64, } + // When compiling natively: #[cfg(not(target_arch = "wasm32"))] +fn setup_tracing(layer: InternalLoggerLayer) { + tracing_subscriber::registry() + .with(LevelFilter::INFO) + .with(filter_fn(|x| x.target() != "sqlx::query")) + .with(tracing_subscriber::fmt::Layer::new()) + .with(layer) + .init(); +} + +// When compiling for web: +#[cfg(target_arch = "wasm32")] +fn setup_tracing(_layer: InternalLoggerLayer) { + // Make sure panics are logged using `console.error`. + console_error_panic_hook::set_once(); + // Redirect tracing to console.log and friends: + tracing_wasm::set_as_global_default(); +} + fn main() { let args = CliArgs::parse(); @@ -63,12 +82,7 @@ fn main() { let logger = InternalLogger::new(args.log_size as usize); let logger_view = logger.view(); - tracing_subscriber::registry() - .with(LevelFilter::INFO) - .with(filter_fn(|x| x.target() != "sqlx::query")) - .with(tracing_subscriber::fmt::Layer::new()) - .with(logger.layer()) - .init(); + setup_tracing(logger.layer()); let state = AppState::new( width_rx,