Files
devplacepy/devplacepy/static/js/CounterManager.js
T
retoor 7fc9b0f715 chore: add retoor header to all devplacepy source files and update style agent header rule
The diff adds the mandatory `retoor <retoor@molodetz.nl>` header comment to every `.py` file under `devplacepy/` (including `__init__.py` and `routers/__init__.py`), and updates the `StyleAgent` in `agents/style.py` to instruct agents to only add the header on created or already-edited files rather than sweeping the entire repo. The `agents/base.py` operating protocol is also revised to reorder and clarify tool discipline rules.
2026-06-11 23:58:46 +00:00

42 lines
1.2 KiB
JavaScript

// retoor <retoor@molodetz.nl>
import { Http } from "./Http.js";
import { Poller } from "./Poller.js";
export class CounterManager {
constructor() {
if (!document.querySelector("[data-counter]")) {
return;
}
document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "visible") {
this.poll();
}
});
this.poller = new Poller(() => this.poll(), 30000, { pauseHidden: true });
}
async poll() {
let counts;
try {
counts = await Http.getJson("/notifications/counts");
} catch (error) {
console.error("counter poll failed", error);
return;
}
this.apply("notifications", counts.notifications);
this.apply("messages", counts.messages);
}
apply(key, count) {
document.querySelectorAll(`[data-counter="${key}"]`).forEach((target) => {
const badge = target.querySelector("[data-counter-badge]");
if (!badge) {
return;
}
badge.textContent = count;
badge.hidden = count === 0;
});
}
}