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.
42 lines
1.2 KiB
JavaScript
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;
|
|
});
|
|
}
|
|
}
|