feat(ui): installierbare PWA mit Manifest und Symbolen, ohne Service Worker (#1062)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 22:59:15 +01:00
parent 05bb6c242b
commit 25398a6f9a
7 changed files with 117 additions and 1 deletions

View File

@ -142,6 +142,10 @@ pub fn routes() -> Router<Arc<AppState>> {
.route("/ui/app.js", get(app_js))
.route("/ui/app.css", get(app_css))
.route("/ui/favicon.svg", get(favicon))
// PWA (→ #1062): Manifest und Symbole sind ohne Anmeldung lesbar, enthalten
// nur Name und Farben. Einen Service Worker gibt es bewusst nicht.
.route("/ui/manifest.webmanifest", get(manifest))
.route("/ui/icons/{name}", get(icon))
}
// --- Sitzungen ---------------------------------------------------------------
@ -411,6 +415,10 @@ fn head(title: &str) -> String {
"<!doctype html><html lang=\"de\"><head><meta charset=\"utf-8\">\
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\
<title>{} · neXus</title><link rel=\"icon\" type=\"image/svg+xml\" href=\"/ui/favicon.svg\">\
<link rel=\"manifest\" href=\"/ui/manifest.webmanifest\">\
<link rel=\"apple-touch-icon\" href=\"/ui/icons/icon-192.png\">\
<meta name=\"theme-color\" content=\"#0f1115\" media=\"(prefers-color-scheme: dark)\">\
<meta name=\"theme-color\" content=\"#f6f3ef\" media=\"(prefers-color-scheme: light)\">\
<link rel=\"stylesheet\" href=\"/ui/app.css\"></head>",
esc(title)
)
@ -1131,6 +1139,50 @@ async fn favicon() -> Response {
.unwrap_or_default()
}
/// Web-App-Manifest: macht die Oberfläche installierbar. Nur öffentliche Angaben.
const MANIFEST: &str = r##"{
"name": "neXus",
"short_name": "neXus",
"description": "AI Gateway für srv04: Verwaltung und Chat",
"lang": "de",
"start_url": "/ui",
"scope": "/ui",
"display": "standalone",
"background_color": "#0f1115",
"theme_color": "#0f1115",
"icons": [
{"src": "/ui/favicon.svg", "sizes": "any", "type": "image/svg+xml", "purpose": "any"},
{"src": "/ui/icons/icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any"},
{"src": "/ui/icons/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any"},
{"src": "/ui/icons/icon-maskable-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable"}
]
}
"##;
const ICON_192: &[u8] = include_bytes!("ui/icons/icon-192.png");
const ICON_512: &[u8] = include_bytes!("ui/icons/icon-512.png");
const ICON_MASKABLE_512: &[u8] = include_bytes!("ui/icons/icon-maskable-512.png");
async fn manifest() -> Response {
secure(Response::builder())
.header(CONTENT_TYPE, "application/manifest+json")
.body(Body::from(MANIFEST))
.unwrap_or_default()
}
async fn icon(axum::extract::Path(name): axum::extract::Path<String>) -> Response {
let bytes = match name.as_str() {
"icon-192.png" => ICON_192,
"icon-512.png" => ICON_512,
"icon-maskable-512.png" => ICON_MASKABLE_512,
_ => return refused(StatusCode::NOT_FOUND, "Unbekanntes Symbol."),
};
secure(Response::builder())
.header(CONTENT_TYPE, "image/png")
.body(Body::from(bytes))
.unwrap_or_default()
}
async fn app_css() -> Response {
secure(Response::builder())
.header(CONTENT_TYPE, "text/css; charset=utf-8")

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

View File

@ -1057,6 +1057,61 @@ async fn ui_get(
(status, headers, resp.text().await.unwrap())
}
/// PWA (→ #1062): Manifest und Symbole sind ohne Sitzung lesbar und enthalten nur
/// öffentliche Angaben; die Seiten verweisen darauf; es gibt keinen Service Worker.
#[tokio::test]
async fn pwa_manifest_und_symbole_sind_ohne_sitzung_lesbar() {
let gw = gateway(0, false).await;
let (status, headers, body) = ui_get(&gw, "/ui/manifest.webmanifest", None).await;
assert_eq!(status, 200);
assert_eq!(headers["content-type"], "application/manifest+json");
let m: serde_json::Value = serde_json::from_str(&body).expect("Manifest ist JSON");
assert_eq!(m["name"], "neXus");
assert_eq!(m["short_name"], "neXus");
assert_eq!(m["lang"], "de");
assert_eq!(m["start_url"], "/ui");
assert_eq!(m["scope"], "/ui");
assert_eq!(m["display"], "standalone");
let icons = m["icons"].as_array().unwrap();
for sizes in ["192x192", "512x512"] {
assert!(
icons
.iter()
.any(|i| i["sizes"] == sizes && i["purpose"] == "any"),
"Symbol {sizes} fehlt"
);
}
assert!(icons.iter().any(|i| i["purpose"] == "maskable"));
// Jedes im Manifest genannte Symbol ist abrufbar und echt (PNG-Kopf oder SVG).
for i in icons {
let src = i["src"].as_str().unwrap();
let resp = no_redirect()
.get(format!("{}{src}", gw.base))
.send()
.await
.unwrap();
assert_eq!(resp.status(), 200, "{src}");
assert_eq!(
resp.headers()["content-type"],
i["type"].as_str().unwrap(),
"{src}"
);
let bytes = resp.bytes().await.unwrap();
if src.ends_with(".png") {
assert_eq!(&bytes[..8], b"\x89PNG\r\n\x1a\n", "{src}");
}
}
assert_eq!(ui_get(&gw, "/ui/icons/unbekannt.png", None).await.0, 404);
assert_eq!(ui_get(&gw, "/ui/icons/..%2Fapp.js", None).await.0, 404);
// Kein Service Worker: es gibt keine Route dafür.
assert_eq!(ui_get(&gw, "/ui/sw.js", None).await.0, 404);
// Die Anmeldeseite verweist auf das Manifest und setzt die Themenfarbe.
let (_, _, login) = ui_get(&gw, "/ui/login", None).await;
assert!(login.contains("rel=\"manifest\" href=\"/ui/manifest.webmanifest\""));
assert!(login.contains("name=\"theme-color\""));
assert!(!login.contains("serviceWorker"));
}
#[tokio::test]
async fn oberflaeche_ohne_sitzung_leitet_zur_anmeldung_und_teile_geben_401() {
let gw = gateway(0, false).await;