Merge branch 'feat/favicon-enregistrement'
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
9e136bd208
4 files changed
+47
No files matched your search
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><circle cx="16" cy="16" r="13" fill="#e5322d" fill-opacity="${opacity}"/></svg>`,
|
||||
);
|
||||
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);
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><circle cx="16" cy="16" r="12" fill="none" stroke="#2f6f5e" stroke-width="4"/><path d="M16 9v7l4 3" fill="none" stroke="#2f6f5e" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
||||
|
After Width: | Height: | Size: 261 B |
@@ -4,6 +4,7 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{% block title %}Tempus{% endblock %} · Tempus</title>
|
||||
<link rel="icon" id="favicon" type="image/svg+xml" href="/static/favicon.svg">
|
||||
<link rel="stylesheet" href="/static/flatpickr/flatpickr.min.css">
|
||||
<link rel="stylesheet" href="/static/app.css?v={{ crate::routes::asset_version() }}">
|
||||
<script src="/static/htmx.min.js" defer></script>
|
||||
|
||||
Reference in new issue
Block a user