Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e136bd208 | ||
|
|
0c9b9c5823 | ||
|
|
aa4f5aeb0a | ||
|
|
b4702fdf71 |
No files matched your search
+19
-6
@@ -44,18 +44,31 @@ 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(
|
.route(
|
||||||
"/static/app.js",
|
"/static/favicon.svg",
|
||||||
get(|| asset("text/javascript", include_str!("../../static/app.js"))),
|
get(|| asset("image/svg+xml", include_str!("../../static/favicon.svg"))),
|
||||||
)
|
|
||||||
.route(
|
|
||||||
"/static/app.css",
|
|
||||||
get(|| asset("text/css", include_str!("../../static/app.css"))),
|
|
||||||
)
|
)
|
||||||
.layer(TraceLayer::new_for_http())
|
.layer(TraceLayer::new_for_http())
|
||||||
.with_state(pool)
|
.with_state(pool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const APP_CSS: &str = include_str!("../../static/app.css");
|
||||||
|
const APP_JS: &str = include_str!("../../static/app.js");
|
||||||
|
|
||||||
|
/// Hash of app.css + app.js, appended as `?v=` to their URLs so a deploy
|
||||||
|
/// bypasses the browser cache.
|
||||||
|
pub fn asset_version() -> &'static str {
|
||||||
|
static VERSION: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
|
||||||
|
use std::hash::{Hash, Hasher};
|
||||||
|
let mut h = std::collections::hash_map::DefaultHasher::new();
|
||||||
|
(APP_CSS, APP_JS).hash(&mut h);
|
||||||
|
format!("{:x}", h.finish())
|
||||||
|
});
|
||||||
|
&VERSION
|
||||||
|
}
|
||||||
|
|
||||||
// En livereload, le CSS/JS doit être relu à chaque rechargement.
|
// En livereload, le CSS/JS doit être relu à chaque rechargement.
|
||||||
const CACHE_CONTROL: &str = if cfg!(feature = "livereload") {
|
const CACHE_CONTROL: &str = if cfg!(feature = "livereload") {
|
||||||
"no-cache"
|
"no-cache"
|
||||||
|
|||||||
@@ -61,3 +61,44 @@ function removeRow(button) {
|
|||||||
for (const input of row.querySelectorAll("input")) input._flatpickr?.destroy();
|
for (const input of row.querySelectorAll("input")) input._flatpickr?.destroy();
|
||||||
row.remove();
|
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 |
+3
-2
@@ -4,12 +4,13 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>{% block title %}Tempus{% endblock %} · Tempus</title>
|
<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/flatpickr/flatpickr.min.css">
|
||||||
<link rel="stylesheet" href="/static/app.css">
|
<link rel="stylesheet" href="/static/app.css?v={{ crate::routes::asset_version() }}">
|
||||||
<script src="/static/htmx.min.js" defer></script>
|
<script src="/static/htmx.min.js" defer></script>
|
||||||
<script src="/static/flatpickr/flatpickr.min.js" defer></script>
|
<script src="/static/flatpickr/flatpickr.min.js" defer></script>
|
||||||
<script src="/static/flatpickr/fr.min.js" defer></script>
|
<script src="/static/flatpickr/fr.min.js" defer></script>
|
||||||
<script src="/static/app.js" defer></script>
|
<script src="/static/app.js?v={{ crate::routes::asset_version() }}" defer></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header class="topbar">
|
<header class="topbar">
|
||||||
|
|||||||
Reference in new issue
Block a user