mirror of
https://github.com/db9979/wibosim.git
synced 2026-12-06 13:34:09 +01:00
- Service Worker (/sw.js, eigene Route mit no-cache und Service-Worker-Allowed), Offline-Seite, Manifest mit id, scope, start_url und Kurzbefehlen, iOS-Meta-Tags, Safe-Area im Standalone-Modus - Web Push ohne neue Abhängigkeit: aes128gcm-Verschlüsselung und VAPID mit node:crypto, geprüft gegen die RFC-Testvektoren; VAPID-Schlüssel im Datenverzeichnis oder per Umgebung - Abos je Spieler (bis 5 Geräte), Abo entfernen bei 404/410, Grenze je Stunde, Ruhezeiten, kein Push bei sichtbarem Tab, kurzer Inhalt mit Deep-Link; Versand über den Kanal „push“ - Einstellungen „Auf diesem Gerät“, iOS-Hinweis „Zum Home-Bildschirm“, Installationsknopf, App-Badge; Admin-Karte unter Betrieb; Datenschutz, Hilfe, Glossar und BETRIEB.md ergänzt - Tests: RFC-Vektoren, Server-Modul, PWA-Auslieferung und Service Worker; lokaler Prüf-Push-Dienst Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUhQVoPUusUzxgxLWkK
62 lines
3.7 KiB
JavaScript
62 lines
3.7 KiB
JavaScript
// Admin-Menü (Team App): Karte „Push-Benachrichtigungen“ unter Betrieb – Zahl der Abos, gesendete und fehlgeschlagene
|
||
// Pushes seit dem Start, Schlüsselquelle, Kontakt (VAPID) und Test-Push an die eigenen Geräte. Server: src/webpush.js.
|
||
// Eigenständig: lädt sich nach dem Einfügen selbst und hört auf eigene Knöpfe (data-pusha).
|
||
import { api } from './net.js';
|
||
import { toast } from './ui.js';
|
||
import { esc, int, when } from './util.js';
|
||
import { icon } from './icons.js';
|
||
|
||
let st = null, err = '', busy = false;
|
||
|
||
export function pushAdminHtml() {
|
||
setTimeout(load, 0);
|
||
return `<div class="push-adm" aria-live="polite">${body()}</div>`;
|
||
}
|
||
|
||
function body() {
|
||
const head = `<div class="admin-actions"><button type="button" class="btn ghost" data-pusha="test" ${busy ? 'disabled aria-busy="true"' : ''}>${icon('bell')} Test-Push an mich</button>
|
||
<button type="button" class="btn ghost small" data-pusha="reload">Status neu laden</button></div>`;
|
||
if (err) return `${head}<p class="err-line">${esc(err)}</p>`;
|
||
if (!st) return `${head}<p class="muted small">Status wird geladen …</p>`;
|
||
const e = st.lastError;
|
||
return `${head}
|
||
<div class="kpis" style="margin-top:10px">
|
||
<div><small>Abos (Geräte)</small><b>${int(st.subs)}</b><small>${int(st.players)} Spieler</small></div>
|
||
<div><small>Gesendet</small><b>${int(st.sent)}</b><small>seit ${esc(when(st.since))}</small></div>
|
||
<div><small>Fehlgeschlagen</small><b class="${st.failed ? 'down' : ''}">${int(st.failed)}</b><small>${int(st.removed)} Abos entfernt (abgelaufen)</small></div>
|
||
<div><small>Zurückgehalten</small><b>${int(st.skippedVisible + st.skippedRate)}</b><small>${int(st.skippedVisible)} Tab offen · ${int(st.skippedRate)} Grenze</small></div>
|
||
</div>
|
||
<dl class="kv">
|
||
<dt>Zustand</dt><dd>${st.enabled ? `<span class="up">eingeschaltet</span> · höchstens ${int(st.perHour)} je Spieler und Stunde` : '<span class="down">abgeschaltet</span>'}</dd>
|
||
<dt>Kontakt (VAPID)</dt><dd><code>${esc(st.subject)}</code>${/localhost/.test(st.subject) ? ' <span class="gold-t small">– bitte die https-Adresse des Servers eintragen (Einstellungen → Datenpflege & Betrieb → Push-Benachrichtigungen)</span>' : ''}</dd>
|
||
<dt>Schlüssel</dt><dd class="small">${esc(st.keySource)} · <code title="Öffentlicher VAPID-Schlüssel">${esc(String(st.publicKey).slice(0, 18))}…</code></dd>
|
||
${st.lastOkAt ? `<dt>Zuletzt zugestellt</dt><dd>${esc(when(st.lastOkAt))}</dd>` : ''}
|
||
${e ? `<dt>Letzter Fehler</dt><dd class="small">${esc(when(e.at))} · ${esc(e.host)} · ${e.status ? `Antwort ${int(e.status)}` : esc(e.text ?? 'keine Verbindung')}</dd>` : ''}
|
||
</dl>
|
||
<p class="muted small">Push braucht HTTPS (auf dem Pi über Caddy). Die Schlüssel liegen im Datenverzeichnis (<code>vapid.json</code>) – mit sichern; geht die Datei verloren, müssen alle Spieler Push neu einschalten.</p>`;
|
||
}
|
||
|
||
function paint() { for (const el of document.querySelectorAll('.push-adm')) el.innerHTML = body(); }
|
||
|
||
async function load() {
|
||
try { st = await api('/api/admin/push'); err = ''; } catch (e) { err = e.message; }
|
||
paint();
|
||
}
|
||
|
||
async function test() {
|
||
busy = true; paint();
|
||
try {
|
||
const r = await api('/api/admin/push/test', { method: 'POST' });
|
||
st = r.view;
|
||
toast(r.sent ? `Test-Push an ${int(r.sent)} Gerät${r.sent === 1 ? '' : 'e'} gesendet.` : 'Test-Push nicht zugestellt – siehe „Letzter Fehler“.', r.sent ? 'ok' : 'warn');
|
||
} catch (e) { toast(e.message, 'err'); }
|
||
busy = false; paint();
|
||
}
|
||
|
||
document.addEventListener('click', (e) => {
|
||
const b = e.target.closest('[data-pusha]');
|
||
if (!b) return;
|
||
e.preventDefault();
|
||
if (b.dataset.pusha === 'test') test(); else load();
|
||
});
|