mirror of
https://git.alemi.dev/dashboard.git
synced 2024-11-21 23:14:53 +01:00
build: added Trunk and template files for wasm
still doesn't compile but some steps in the right direction
This commit is contained in:
parent
2bcca43602
commit
4466b792fd
13 changed files with 234 additions and 12 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -9,3 +9,6 @@ Cargo.lock
|
||||||
|
|
||||||
# These are backup files generated by rustfmt
|
# These are backup files generated by rustfmt
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# These are build files generated by Trunk
|
||||||
|
dist/
|
||||||
|
|
14
Cargo.toml
14
Cargo.toml
|
@ -16,18 +16,24 @@ dirs = "4"
|
||||||
git-version = "0.3.5"
|
git-version = "0.3.5"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
tracing = "0.1" # egui / eframe use tracing
|
tracing = "0.1" # egui / eframe use tracing
|
||||||
tracing-subscriber = "0.3"
|
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
csv = "1.1"
|
csv = "1.1"
|
||||||
jql = { version = "4", default-features = false }
|
jql = { version = "4", default-features = false }
|
||||||
rfd = "0.9"
|
rfd = "0.9"
|
||||||
eframe = "0.19"
|
eframe = { version = "0.19", features = ["persistence"] }
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
clap = { version = "4", features = ["derive"] }
|
clap = { version = "4", features = ["derive"] }
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
sea-orm = { version = "0.10", features = [ "runtime-tokio-rustls", "sqlx-sqlite", "macros" ] }
|
sea-orm = { version = "0.10", features = [ "runtime-tokio-rustls", "sqlx-sqlite", "macros" ] }
|
||||||
reqwest = { version = "0.11", features = ["json"] }
|
reqwest = { version = "0.11", features = ["json"] }
|
||||||
|
|
||||||
[profile.dev.package."*"]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
opt-level = 3
|
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
|
||||||
|
|
2
Trunk.toml
Normal file
2
Trunk.toml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[build]
|
||||||
|
filehash = false
|
BIN
assets/favicon.ico
Executable file
BIN
assets/favicon.ico
Executable file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
BIN
assets/icon-1024.png
Normal file
BIN
assets/icon-1024.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 314 KiB |
BIN
assets/icon-256.png
Normal file
BIN
assets/icon-256.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 47 KiB |
BIN
assets/icon_ios_touch_192.png
Normal file
BIN
assets/icon_ios_touch_192.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
28
assets/manifest.json
Normal file
28
assets/manifest.json
Normal file
|
@ -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"
|
||||||
|
}
|
BIN
assets/maskable_icon_x512.png
Normal file
BIN
assets/maskable_icon_x512.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 128 KiB |
25
assets/sw.js
Normal file
25
assets/sw.js
Normal file
|
@ -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);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
140
index.html
Normal file
140
index.html
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
|
||||||
|
<!-- Disable zooming: -->
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<!-- change this to your project name -->
|
||||||
|
<title>eframe template</title>
|
||||||
|
|
||||||
|
<!-- config for our rust wasm binary. go to https://trunkrs.dev/assets/#rust for more customization -->
|
||||||
|
<link data-trunk rel="rust" data-wasm-opt="2" />
|
||||||
|
<!-- this is the base url relative to which other urls will be constructed. trunk will insert this from the public-url option -->
|
||||||
|
<base data-trunk-public-url />
|
||||||
|
|
||||||
|
<link data-trunk rel="icon" href="assets/favicon.ico">
|
||||||
|
|
||||||
|
|
||||||
|
<link data-trunk rel="copy-file" href="assets/sw.js" />
|
||||||
|
<link data-trunk rel="copy-file" href="assets/manifest.json" />
|
||||||
|
<link data-trunk rel="copy-file" href="assets/icon-1024.png" />
|
||||||
|
<link data-trunk rel="copy-file" href="assets/icon-256.png" />
|
||||||
|
<link data-trunk rel="copy-file" href="assets/icon_ios_touch_192.png" />
|
||||||
|
<link data-trunk rel="copy-file" href="assets/maskable_icon_x512.png" />
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="manifest" href="manifest.json">
|
||||||
|
<link rel="apple-touch-icon" href="icon_ios_touch_192.png">
|
||||||
|
<meta name="theme-color" media="(prefers-color-scheme: light)" content="white">
|
||||||
|
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#404040">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
html {
|
||||||
|
/* Remove touch delay: */
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
/* Light mode background color for what is not covered by the egui canvas,
|
||||||
|
or where the egui canvas is translucent. */
|
||||||
|
background: #909090;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
body {
|
||||||
|
/* Dark mode background color for what is not covered by the egui canvas,
|
||||||
|
or where the egui canvas is translucent. */
|
||||||
|
background: #404040;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Allow canvas to fill entire web page: */
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
overflow: hidden;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Position canvas in center-top: */
|
||||||
|
canvas {
|
||||||
|
margin-right: auto;
|
||||||
|
margin-left: auto;
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
top: 0%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, 0%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.centered {
|
||||||
|
margin-right: auto;
|
||||||
|
margin-left: auto;
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
color: #f0f0f0;
|
||||||
|
font-size: 24px;
|
||||||
|
font-family: Ubuntu-Light, Helvetica, sans-serif;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------- */
|
||||||
|
/* Loading animation from https://loading.io/css/ */
|
||||||
|
.lds-dual-ring {
|
||||||
|
display: inline-block;
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lds-dual-ring:after {
|
||||||
|
content: " ";
|
||||||
|
display: block;
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
margin: 0px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 3px solid #fff;
|
||||||
|
border-color: #fff transparent #fff transparent;
|
||||||
|
animation: lds-dual-ring 1.2s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes lds-dual-ring {
|
||||||
|
0% {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<!-- The WASM code will resize the canvas dynamically -->
|
||||||
|
<!-- the id is hardcoded in main.rs . so, make sure both match. -->
|
||||||
|
<canvas id="the_canvas_id"></canvas>
|
||||||
|
|
||||||
|
<!--Register Service Worker. this will cache the wasm / js scripts for offline use (for PWA functionality). -->
|
||||||
|
<!-- Force refresh (Ctrl + F5) to load the latest files instead of cached files -->
|
||||||
|
<script>
|
||||||
|
// We disable caching during development so that we always view the latest version.
|
||||||
|
if ('serviceWorker' in navigator && window.location.hash !== "#dev") {
|
||||||
|
window.addEventListener('load', function () {
|
||||||
|
navigator.serviceWorker.register('sw.js');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
|
||||||
|
<!-- Powered by egui: https://github.com/emilk/egui/ -->
|
|
@ -5,7 +5,7 @@ pub mod metric;
|
||||||
mod scaffold;
|
mod scaffold;
|
||||||
|
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use eframe::egui::{CentralPanel, Context, SidePanel, TopBottomPanel};
|
use eframe::egui::{CentralPanel, Context, SidePanel, TopBottomPanel, Window};
|
||||||
use tokio::sync::watch;
|
use tokio::sync::watch;
|
||||||
|
|
||||||
use crate::{data::entities, worker::visualizer::AppStateView};
|
use crate::{data::entities, worker::visualizer::AppStateView};
|
||||||
|
@ -35,6 +35,7 @@ pub struct App {
|
||||||
edit: bool,
|
edit: bool,
|
||||||
sidebar: bool,
|
sidebar: bool,
|
||||||
padding: bool,
|
padding: bool,
|
||||||
|
// windows: Vec<Window<'open>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
|
@ -56,6 +57,7 @@ impl App {
|
||||||
edit: false,
|
edit: false,
|
||||||
sidebar: true,
|
sidebar: true,
|
||||||
padding: false,
|
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());
|
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 {
|
// if let Some(index) = self.deleting_metric {
|
||||||
// Window::new(format!("Delete Metric #{}?", index))
|
// Window::new(format!("Delete Metric #{}?", index))
|
||||||
// .show(ctx, |ui| confirmation_popup_delete_metric(self, ui, index));
|
// .show(ctx, |ui| confirmation_popup_delete_metric(self, ui, index));
|
||||||
|
|
28
src/main.rs
28
src/main.rs
|
@ -15,7 +15,7 @@ use sea_orm::Database;
|
||||||
|
|
||||||
use worker::visualizer::AppState;
|
use worker::visualizer::AppState;
|
||||||
use worker::surveyor_loop;
|
use worker::surveyor_loop;
|
||||||
use util::InternalLogger;
|
use util::{InternalLogger, InternalLoggerLayer};
|
||||||
use gui::{
|
use gui::{
|
||||||
// util::InternalLogger,
|
// util::InternalLogger,
|
||||||
App
|
App
|
||||||
|
@ -49,8 +49,27 @@ struct CliArgs {
|
||||||
log_size: u64,
|
log_size: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// When compiling natively:
|
// When compiling natively:
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[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() {
|
fn main() {
|
||||||
let args = CliArgs::parse();
|
let args = CliArgs::parse();
|
||||||
|
|
||||||
|
@ -63,12 +82,7 @@ fn main() {
|
||||||
let logger = InternalLogger::new(args.log_size as usize);
|
let logger = InternalLogger::new(args.log_size as usize);
|
||||||
let logger_view = logger.view();
|
let logger_view = logger.view();
|
||||||
|
|
||||||
tracing_subscriber::registry()
|
setup_tracing(logger.layer());
|
||||||
.with(LevelFilter::INFO)
|
|
||||||
.with(filter_fn(|x| x.target() != "sqlx::query"))
|
|
||||||
.with(tracing_subscriber::fmt::Layer::new())
|
|
||||||
.with(logger.layer())
|
|
||||||
.init();
|
|
||||||
|
|
||||||
let state = AppState::new(
|
let state = AppState::new(
|
||||||
width_rx,
|
width_rx,
|
||||||
|
|
Loading…
Reference in a new issue