From 0c9b9c5823fc80a442b6ffa7d3168cec7daf476e Mon Sep 17 00:00:00 2001 From: Romulus21 Date: Fri, 13 Nov 2026 18:54:34 +0100 Subject: [PATCH] Fait clignoter le favicon en rouge pendant un enregistrement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Favicon par défaut (static/favicon.svg) ; tant que /api/timer renvoie une entrée en cours, il alterne chaque seconde entre un point rouge plein et pâle, sur toutes les pages. État relu au chargement, après chaque requête htmx, au retour sur l'onglet et toutes les 20 s. Co-Authored-By: Claude Opus 5.5 --- src/routes/mod.rs | 4 ++++ static/app.js | 41 +++++++++++++++++++++++++++++++++++++++++ static/favicon.svg | 1 + templates/base.html | 1 + 4 files changed, 47 insertions(+) create mode 100644 static/favicon.svg diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 1097837..600386a 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -46,6 +46,10 @@ pub fn app(pool: SqlitePool) -> Router { ) .route("/static/app.js", get(|| asset("text/javascript", APP_JS))) .route("/static/app.css", get(|| asset("text/css", APP_CSS))) + .route( + "/static/favicon.svg", + get(|| asset("image/svg+xml", include_str!("../../static/favicon.svg"))), + ) .layer(TraceLayer::new_for_http()) .with_state(pool) } diff --git a/static/app.js b/static/app.js index a02c000..c46ebfc 100644 --- a/static/app.js +++ b/static/app.js @@ -61,3 +61,44 @@ function removeRow(button) { for (const input of row.querySelectorAll("input")) input._flatpickr?.destroy(); row.remove(); } + +// Favicon : point rouge clignotant tant qu'un enregistrement est en cours, +// sur toutes les pages (état lu sur /api/timer). +const favicon = document.getElementById("favicon"); +const IDLE_ICON = favicon.href; +const recIcon = (opacity) => + "data:image/svg+xml," + + encodeURIComponent( + ``, + ); +const REC_ON = recIcon(1); +const REC_OFF = recIcon(0.2); +let recording = false; +let blinkOn = false; + +function setRecording(value) { + if (value === recording) return; + recording = value; + blinkOn = true; + favicon.href = recording ? REC_ON : IDLE_ICON; +} +setInterval(() => { + if (!recording) return; + blinkOn = !blinkOn; + favicon.href = blinkOn ? REC_ON : REC_OFF; +}, 1000); + +async function refreshRecording() { + try { + const res = await fetch("/api/timer", { headers: { accept: "application/json" } }); + if (res.ok) setRecording((await res.json()) !== null); + } catch { + // Serveur injoignable : on garde l'état connu. + } +} +refreshRecording(); +setInterval(refreshRecording, 20000); +document.addEventListener("visibilitychange", () => { + if (!document.hidden) refreshRecording(); +}); +document.body.addEventListener("htmx:afterRequest", refreshRecording); diff --git a/static/favicon.svg b/static/favicon.svg new file mode 100644 index 0000000..d02c927 --- /dev/null +++ b/static/favicon.svg @@ -0,0 +1 @@ + diff --git a/templates/base.html b/templates/base.html index 796db32..35c4e35 100644 --- a/templates/base.html +++ b/templates/base.html @@ -4,6 +4,7 @@ {% block title %}Tempus{% endblock %} · Tempus +