Build on Phases 1–6. Telemetry already arrived on
restrict/<device>/telemetry; this phase stores it in a daily rollup and
shows it.
- store: migration 003 adds telemetry_daily (device, day, app seconds,
site seconds). InsertTelemetry maintains the affected days in the same
transaction; RebuildRollups backfills and repairs it. UsageRange and
TopUsage serve the week grid and top lists. CapAudit enforces the
size-capped append-only audit log from AGENTS.md §7.
- web: GET /devices/{id}/usage — Monday-to-Sunday totals plus the top 10
apps and top 10 sites, using CSP-safe native <progress> bars.
- theme.js: light/dark from the OS preference, with a nav toggle, loaded
as an external script so the strict CSP still holds.
- cmd/control: `rollup` subcommand; rollup rebuild and audit cap at
start-up and every 15 minutes.
- Version 0.5.0-phase7 (compose, Makefile, docs).
Tests: go test ./... and go vet ./... pass in golang:1.25-alpine.
Co-Authored-By: Paperclip <noreply@paperclip.ing>
56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
// Theme controller. The design tokens ship both palettes; nothing switches
|
|
// between them unless this runs. It follows the OS preference by default and
|
|
// remembers an explicit choice. Loaded with defer from /static/, so it is
|
|
// allowed by the page's `script-src 'self'` policy (no inline script).
|
|
(function () {
|
|
"use strict";
|
|
var KEY = "webrestrict.theme";
|
|
var root = document.documentElement;
|
|
var media = window.matchMedia("(prefers-color-scheme: dark)");
|
|
var stored = null;
|
|
try {
|
|
stored = window.localStorage.getItem(KEY);
|
|
} catch (e) {
|
|
stored = null;
|
|
}
|
|
|
|
function apply() {
|
|
var theme = stored || (media.matches ? "dark" : "light");
|
|
root.setAttribute("data-theme", theme);
|
|
var buttons = document.querySelectorAll("[data-theme-toggle]");
|
|
for (var i = 0; i < buttons.length; i++) {
|
|
buttons[i].textContent = theme === "dark" ? "Light" : "Dark";
|
|
buttons[i].setAttribute(
|
|
"aria-label",
|
|
"Switch to " + (theme === "dark" ? "light" : "dark") + " theme"
|
|
);
|
|
}
|
|
}
|
|
|
|
document.addEventListener("click", function (event) {
|
|
var target = event.target && event.target.closest
|
|
? event.target.closest("[data-theme-toggle]")
|
|
: null;
|
|
if (!target) {
|
|
return;
|
|
}
|
|
stored = root.getAttribute("data-theme") === "dark" ? "light" : "dark";
|
|
try {
|
|
window.localStorage.setItem(KEY, stored);
|
|
} catch (e) {
|
|
/* private mode: the choice just does not persist */
|
|
}
|
|
apply();
|
|
});
|
|
|
|
if (media.addEventListener) {
|
|
media.addEventListener("change", function () {
|
|
if (!stored) {
|
|
apply();
|
|
}
|
|
});
|
|
}
|
|
|
|
apply();
|
|
})();
|