Dashboard page for sccache-dash (crates/ui)

An eframe/egui page compiled to WebAssembly with trunk. It draws the one
View the server sends: controls on top, three big figures, six cards, and
the collapsible sections Problems, Where compiles went, Over time, Speed,
Extras and Raw counters. The range, refresh interval and theme are
remembered between visits with eframe storage.

mise.toml names trunk 0.22.2 as the build tool.
This commit is contained in:
swaits committed 2026-11-28 11:30:54 -07:00
1 parent a8e7bd66cf
commit b80749ebb5
16 files changed
+2242

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
//! The sccache-dash dashboard page. `trunk` compiles this to WebAssembly and
//! the sccache-dash server serves it at http://127.0.0.1:8226.
pub mod app;
pub mod cards;
pub mod extras;
pub mod fmt;
pub mod net;
pub mod overtime;
pub mod problems;
pub mod raw;
pub mod speed;
pub mod style;
pub mod where_went;
/// The canvas in `index.html` the page is drawn on.
pub const CANVAS_ID: &str = "the_canvas_id";
/// Open the dashboard page in the browser.
pub fn open() {
#[cfg(target_arch = "wasm32")]
web::open();
#[cfg(not(target_arch = "wasm32"))]
eprintln!(
"sccache-dash-ui is a web page: build it with `trunk build` in crates/ui. \
There is no native window yet."
);
}
#[cfg(target_arch = "wasm32")]
mod web {
use super::{app::Dashboard, CANVAS_ID};
pub fn open() {
use wasm_bindgen::JsCast;
let canvas = web_sys::window()
.and_then(|window| window.document())
.and_then(|document| document.get_element_by_id(CANVAS_ID))
.and_then(|element| element.dyn_into::<web_sys::HtmlCanvasElement>().ok())
.unwrap_or_else(|| panic!("index.html has no canvas named #{CANVAS_ID}"));
wasm_bindgen_futures::spawn_local(async move {
let options = eframe::WebOptions::default();
eframe::WebRunner::new()
.start(canvas, options, Box::new(|cc| Ok(Box::new(Dashboard::new(cc)))))
.await
.unwrap_or_else(|error| panic!("eframe failed to start: {error:?}"));
});
}
}