commit ac64fa1b0e83e46275aeca353db2b15805d81396
parent 19d45eb1425bddcb52a86746fc7b5bfd58361b73
Author: Damian Myrda <damian@prime8.dev>
Date: Sun, 25 Oct 2026 07:25:29 +0000
wakatime: keep last value on failed refresh, unhide on recovery, catch up on wake/visibility
Diffstat:
2 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/internal/web/scripts/modules/layout.js b/internal/web/scripts/modules/layout.js
@@ -115,14 +115,16 @@ async function loadWakaFooter(data = null) {
try {
const stats = data || (await getWakaTimeData());
- if (!stats || !stats.AllTime || !stats.AllTime.TotalText) {
- link.style.display = "none";
+ const text = stats?.AllTime?.TotalText;
+ if (text) {
+ link.textContent = text;
+ link.style.display = "";
return;
}
-
- link.textContent = stats.AllTime.TotalText;
+ // nothing new: keep whatever is already shown, hide only if empty
+ if (!link.textContent.trim()) link.style.display = "none";
} catch {
- link.style.display = "none";
+ if (!link.textContent.trim()) link.style.display = "none";
}
}
diff --git a/internal/web/scripts/modules/wakatime.js b/internal/web/scripts/modules/wakatime.js
@@ -25,9 +25,11 @@ export async function getWakaTimeData(force = false) {
wakatimeCache.data = data;
wakatimeCache.timestamp = Date.now();
}
- return data;
+ // a failed or empty fetch (offline right after wake, a 5xx) keeps the
+ // last good value instead of wiping it
+ return data || wakatimeCache.data;
})
- .catch(() => null)
+ .catch(() => wakatimeCache.data)
.finally(() => {
wakatimeCache.pending = null;
});
@@ -52,6 +54,17 @@ export function startWakaTimeRefreshTimer() {
wakatimeRefreshTimer = window.setInterval(() => {
void refreshWakaTimeData();
}, WAKATIME_TTL_MS);
+
+ // timers are throttled or frozen while the tab is hidden or the laptop
+ // sleeps; catch up as soon as it is visible and online again
+ const catchUp = () => {
+ if (document.visibilityState !== "visible") return;
+ if (isFresh(wakatimeCache.timestamp)) return;
+ void refreshWakaTimeData();
+ };
+ document.addEventListener("visibilitychange", catchUp);
+ window.addEventListener("online", catchUp);
+ window.addEventListener("focus", catchUp);
}
function isFresh(timestamp) {