Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/nornir

nornir-demo/src/main.rs

//! **nornir-demo** — nornir's live web + native demo GUI.
//!
//! The nornir zone/jera showcase surface ([`ZoneDemo`]) mounted on the reusable
//! [`facett_wasm_demo`] harness: one surface, two hosts, from the same source —
//!
//! - **native:** `cargo run -p nornir-demo`
//! - **wasm:**   `cargo xtask demo-wasm` (build) / `cargo xtask deploy-pages` (publish),
//!               served at <https://nordisk.codeberg.page/nornir>
//!
//! [`ZoneDemo`] gives nornir the SAME common zone/jera framework korp runs (L5 —
//! consume the shared widgets, never hand-roll): a central
//! [`facett_zoneui::JeraCentral`] jobs/zones/infra panel + a 🧰 Tools-menu →
//! [`facett_zoneui::ZonePane`] (default demo zone). The pre-existing release
//! dependency-DAG panel ([`ReleaseDepDag`]) stays reachable via the View menu
//! (additive, no regression). There is NO bare "demo" button. It is its **own**
//! crate — NOT wired into `nornir` / `nornir-server` (`publish = false`).

use facett_wasm_demo::FacetApp;

mod panel;
mod zone_demo;
use zone_demo::ZoneDemo;

/// The surface: nornir's zone/jera showcase (central JeraCentral + Tools-menu ZonePane).
fn panel() -> ZoneDemo {
    ZoneDemo::new()
}

// ── native host ──────────────────────────────────────────────────────────────
// The desktop window. `run` returns eframe's `Result`; we don't name the `eframe`
// type (the harness owns that dep), just report a boot failure and exit non-zero.
#[cfg(not(target_arch = "wasm32"))]
fn main() {
    if let Err(e) = facett_wasm_demo::NativeDemo::new("nornir — zones & jera (demo)")
        .run(move |_cc| FacetApp::boxed(Box::new(panel())))
    {
        eprintln!("nornir-demo: failed to start the native window: {e}");
        std::process::exit(1);
    }
}

// On wasm the entry point is `start` (below); `main` still has to exist to link.
#[cfg(target_arch = "wasm32")]
fn main() {}

// ── web host ─────────────────────────────────────────────────────────────────
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen::prelude::wasm_bindgen(start)]
pub fn start() {
    facett_wasm_demo::WebDemo::new("demo_canvas")
        .mount(move |_cc, _hash| FacetApp::boxed(Box::new(panel())));
}

/// The browser-readable state hook: `window.__nornir_state()` returns the panel's live
/// `state_json` (the nornir release dep-DAG shape), so a headless Chromium drive
/// verifies the shipped bundle without a human.
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen::prelude::wasm_bindgen(js_name = __nornir_state)]
pub fn nornir_state() -> String {
    facett_wasm_demo::latest_state()
}