diff --git a/.squad/stack.md b/.squad/stack.md index b4d4f86..e345a08 100644 --- a/.squad/stack.md +++ b/.squad/stack.md @@ -54,6 +54,11 @@ after the PR is open. `gocognit` also counts the bare `if err != nil` check, whi existing function over the limit, add a named exclusion in `.golangci.yml` and note it in `.squad/project.md`. Other SonarQube Cloud findings (and hotspots, duplication) have no local Go equivalent: the *Sonar gate* below reports their issues and hotspots and the quality gate, duplication included, on the draft pull request. +Sonar rules not reported locally, with how to avoid them while writing code: +- `go:S8193` (unnecessary variable declaration): a variable declared in an `if` init statement that is used only in the + condition. Write the expression directly in the condition, e.g. `if normCSS(v) != "inherit" {`. +- `go:S978` (identifier shadows a predeclared identifier): do not name a parameter or variable `min`, `max`, `len`, + `cap`, `new`, `copy`, `string`, `error` and the like; use a qualified name such as `minCount`. Changed shell scripts (`*.sh`), GitHub workflows (`.github/workflows/*.yml`) and Dockerfiles are checked with `shellcheck`, `actionlint` and `hadolint`; the SessionStart hook installs the three as pinned, checksum-verified diff --git a/README.md b/README.md index 647bc17..734d9c3 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ automation systems like openHAB). Runs as a systemd service. transition, so alerts reach Slack, Discord, Home Assistant, ntfy, etc. Delivery is fully off the collection path, so a slow webhook never blocks metric sampling -- **Light/dark theme toggle** - follows the OS setting by default, with a +- **Light/dark mode toggle** - follows the OS setting by default, with a manual override remembered in the browser - **Configurable dashboard layout** - show/hide and reorder metric cards from a settings modal, remembered in the browser diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index b0ada52..70623fe 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -23,7 +23,7 @@ under [`areas/`](areas/README.md); this document links them instead of repeating - [HTTP API](areas/http-api.md) — routes and when they are registered, authentication, compression, caching, the concurrency limit, security headers, `/healthz`, Prometheus, server stats, TLS and timeouts. - [Dashboard](areas/dashboard.md) — asset serving and caching, polling, the history merge, API key handling, - rendering, coloring, alert badges, layout and theme. + rendering, coloring, alert badges, layout, mode and look. - [openHAB](areas/openhab.md) — detecting a local openHAB, its states and values, the poll cadence, the loopback-only requests and the handling of its API token. - [Configuration](areas/configuration.md) — sources and their precedence, every option with its default and valid diff --git a/docs/UNIT_TESTS.md b/docs/UNIT_TESTS.md index a7768e9..8f7ec88 100644 --- a/docs/UNIT_TESTS.md +++ b/docs/UNIT_TESTS.md @@ -46,6 +46,9 @@ not be merged; see the checklist in [`.github/pull_request_template.md`](../.git only their key set. A JS test framework is deliberately not part of this repository (see below), and these scans are the only way to guard client-side behavior that unit tests can't reach. + `internal/web/palette_test.go` pins the dashboard's colour tokens and the contrast ratio of each text and + background pair, and `internal/web/icons_test.go` scans the assets for emoji, so no symbol stands in for an + inline SVG icon. 4. **Integration / hardware tests** diff --git a/docs/areas/README.md b/docs/areas/README.md index ffb8853..7434a22 100644 --- a/docs/areas/README.md +++ b/docs/areas/README.md @@ -34,7 +34,7 @@ operator or another component can rely on — formats, limits, error behavior, g | [Alerts](alerts.md) | Thresholds, debounce, `ok`/`warn`/`crit` states, `fired`/`cleared` events, vanished resources, what `GET /api/v1/alerts` reports | Delivery to webhooks ([Notifications](notifications.md)) | | [Notifications](notifications.md) | Webhook delivery: payload and templates, severity filter, per-webhook queues, retries, rate limit, timeouts, logging | When an alert fires ([Alerts](alerts.md)) | | [HTTP API](http-api.md) | Routes and server-wide rules: versioning, API key, compression, caching, concurrency limit, security headers, TLS, `/healthz`, `/metrics`, server stats, timeouts | Per-endpoint JSON shapes ([`API.md`](../API.md)), the web UI ([Dashboard](dashboard.md)) | -| [Dashboard](dashboard.md) | The web UI: asset serving, polling, hidden-tab pause, API key prompt and browser storage, rendering, value coloring, theme, card layout | Headers and CSP ([HTTP API](http-api.md)), data shapes ([`API.md`](../API.md)) | +| [Dashboard](dashboard.md) | The web UI: asset serving, polling, hidden-tab pause, API key prompt and browser storage, rendering, value coloring, mode and look, card layout | Headers and CSP ([HTTP API](http-api.md)), data shapes ([`API.md`](../API.md)) | | [Configuration](configuration.md) | Config sources and precedence (file, `PIMONITOR_API_KEY`, flags), parsing rules, every option with type, default and valid range, startup failure | What an option does in its area (the area document) | | [Deployment](deployment.md) | Release archive, `download-latest.sh`, `install.sh`, the systemd units and their privileges, the root apt timer, data directory, process lifecycle, upgrades | Release builds and tags ([`CONTRIBUTING.md`](../CONTRIBUTING.md)), threat model ([`SECURITY.md`](../../SECURITY.md)) | | [openHAB](openhab.md) | The status of a local openHAB: detection, states, the values and their sources, poll cadence, request limits and the loopback guard, logging, the API token | The response shape ([`API.md`](../API.md)), the card ([Dashboard](dashboard.md)), option ranges ([Configuration](configuration.md)) | diff --git a/docs/areas/dashboard.md b/docs/areas/dashboard.md index 2f8479e..995d3da 100644 --- a/docs/areas/dashboard.md +++ b/docs/areas/dashboard.md @@ -4,7 +4,7 @@ The web UI served at `/`: how its assets are delivered, which API endpoints it reads and how often, how it handles a configured API key, failures and hidden tabs, how it renders server data, colors values and shows alerts, and the -per-browser preferences (theme, card layout) it keeps. The user viewing the Pi in a browser relies on it; it is a +per-browser preferences (mode, card layout) it keeps. The user viewing the Pi in a browser relies on it; it is a client of the [HTTP API](http-api.md) like any third-party integration and has no server-side state of its own. ## Behavior @@ -192,16 +192,38 @@ client of the [HTTP API](http-api.md) like any third-party integration and has n element that opened it on close. Except for the API key dialog, Escape, a click outside the dialog or its close button closes it. -### Theme +### Mode -- The page has a light and a dark palette. With no stored choice it follows the operating system's +- The page has a light and a dark palette (the two modes). With no stored choice it follows the operating system's `prefers-color-scheme` and follows live changes of it. -- The theme button switches to the other palette and stores the choice under `pimonitor-theme` (`light` or `dark`) +- The mode button switches to the other palette and stores the choice under `pimonitor-theme` (`light` or `dark`) in `localStorage`; from then on the stored choice wins over the operating system setting. The page offers no control to return to following the operating system. - A stored choice is applied before the first paint, so the page never flashes the other palette. Charts and gauges are redrawn in the new palette immediately on a switch. +### Look + +- Every color comes from a token of the palette blocks of `style.css` (light, explicit dark and OS dark, the two + dark blocks identical); no rule outside them holds a color literal. Both the text and the fills of the page use + these tokens, so a mode switch changes tokens only. +- Status text (values, percentages, badges, the alert banner, the API-key error) uses the `*-ink` variant of + `ok`/`warn`/`crit`; bar fills and the card border of an alerting card use the base color. Text on an accent fill + uses `--on-accent`. +- A bar label shows the percentage emphasised, colored only at `warn` and `crit`, and the byte sizes muted beside it. +- The load gauge draws a 9 px arc on the `--track` color and shows its value inside the arc; the value's font size + scales with the gauge width. +- A sparkline is a 2 px line with a fill that fades towards the bottom and a dot with a ring at the newest point, + inset so the dot is never clipped. +- A card's own color appears only on its 28 px icon chip and on the hover/focus highlight of a clickable card; cards + have no colored top border. Clickable cards end their heading with a chevron. +- Icons are inline SVG drawn in `currentColor`, hidden from assistive technology; the page uses no emoji. The mode + button shows the moon in light mode and the sun in dark mode, chosen by CSS. The network card names its rates + Download and Upload for screen readers next to the arrow icons. +- The header buttons, the heading buttons of clickable cards, the updates button and the dialog buttons (close, + range, move, reset, unlock) are at least 44 px high, and 44 px wide where icon-only. The text and status colors + reach a contrast of 4.5:1 on their backgrounds in both modes, guarded by a test (`palette_test.go`). + ### Card layout - The cards are System, Updates, Uptime, CPU Usage, Load Average, Temperature, Memory & Swap, Filesystems, @@ -238,7 +260,9 @@ client of the [HTTP API](http-api.md) like any third-party integration and has n ## Related decisions -None yet. +- [0038](../decisions/0038-dashboard-mode-and-theme-as-token-overrides.md): mode and theme as token overrides +- [0039](../decisions/0039-card-colour-only-on-icon-chip.md): card colour only on the icon chip +- [0040](../decisions/0040-dashboard-icons-inline-svg.md): inline SVG icons ## Not here diff --git a/docs/decisions/0038-dashboard-mode-and-theme-as-token-overrides.md b/docs/decisions/0038-dashboard-mode-and-theme-as-token-overrides.md new file mode 100644 index 0000000..9f3a41f --- /dev/null +++ b/docs/decisions/0038-dashboard-mode-and-theme-as-token-overrides.md @@ -0,0 +1,38 @@ +# 0038: Dashboard "mode" is light or dark, a "theme" is a set of custom-property overrides + +- **Status:** Accepted +- **Date:** 2026-11-28 +- **Area:** Dashboard +- **Source:** Issue #217 +- **Supersedes:** — + +## Context + +Until v1.4 the dashboard called its light/dark palette switch the "theme" (`pimonitor-theme`, `data-theme`, the +header button). Issue #217 introduces the visual design Clear, and later issues of the v1.5.0 milestone add the +designs Console and Berry and a selection between them, each in a light and a dark variant. Two concepts now need two +names, and each design has to be swappable without touching the markup or the scripts. The page runs under +`style-src 'self'`, so no style can be injected at run time. + +## Options considered + +1. **"Mode" for light/dark, "theme" for the design; every colour, radius, shadow, padding and gap a custom property + on `:root`, defined in a light block and two identical dark blocks** — a theme becomes a set of overrides of + these properties; canvas widgets read the same properties when they draw. Cost: more tokens, and the two dark + blocks must be kept identical (guarded by a test). +2. **Keep "theme" for light/dark and call the designs "skins"** — no rename in the documentation. Cost: the stored + key and the attribute keep a name that no longer matches the user-facing concept of the milestone's issues. +3. **One stylesheet per design** — each design free in its rules. Cost: three copies of every layout rule to keep in + step, more embedded bytes on a Pi Zero, and a design switch that reloads a stylesheet. + +## Decision + +Option 1. Light/dark is the *mode*; its storage key `pimonitor-theme` and attribute `data-theme` keep their names, +since renaming them would reset every stored choice. The look is described in +[Dashboard](../areas/dashboard.md#look); the per-card colours are tokens of the palette blocks like every other +colour. + +## Consequences + +- A later theme only adds override blocks; `style.css` holds no colour literal outside the palette blocks. +- The stored key keeps the old word: code and documentation say "mode" and name the key as it is. diff --git a/docs/decisions/0039-card-colour-only-on-icon-chip.md b/docs/decisions/0039-card-colour-only-on-icon-chip.md new file mode 100644 index 0000000..9aed5e5 --- /dev/null +++ b/docs/decisions/0039-card-colour-only-on-icon-chip.md @@ -0,0 +1,37 @@ +# 0039: The per-card colour appears only on the icon chip; status colours have a fill and an ink variant + +- **Status:** Accepted +- **Date:** 2026-11-28 +- **Area:** Dashboard +- **Source:** Issue #217 +- **Supersedes:** — + +## Context + +Every card had a 3 px top border in its own colour, so nine to ten strong colours competed with `ok`, `warn` and +`crit`, the colours that carry meaning. The status colours also served as text colours, and in light mode `#16a34a` +and `#d97706` on white reach only about 3.3:1 and 3.2:1, below the 4.5:1 that small text needs. + +## Options considered + +1. **Card colour only on a tinted icon chip and on the hover/focus highlight; a darker (light mode) or lighter (dark + mode) `*-ink` token per status level for text, the base token for fills** — the status colours stand out, text + reaches 4.5:1, fills keep their familiar hue. Cost: two tokens per level to keep consistent. +2. **Drop the per-card colours altogether** — calmest page. Cost: the cards lose the cue that tells them apart at a + glance, which the issue keeps. +3. **Darken the base status colours for everything** — one token per level. Cost: bar fills and gauge arcs turn + muddy in light mode, and dark mode needs the opposite shift. + +## Decision + +Option 1: no coloured card border; the card colour tints the icon chip and the highlight of clickable cards; text in +a status colour uses `--ok-ink`, `--warn-ink` or `--crit-ink`, fills use `--ok`, `--warn` or `--crit`. The rules are +in [Dashboard](../areas/dashboard.md#look). + +## Consequences + +- Every status rule for text is at least as specific as the rule that gives the element its default colour; until + this change the openHAB process-memory value and the `Things offline` toggle never showed their documented + colour because of that. +- A contrast test in `internal/web` computes the ratios from the parsed tokens, so a later palette edit cannot drop + below 4.5:1 unnoticed. diff --git a/docs/decisions/0040-dashboard-icons-inline-svg.md b/docs/decisions/0040-dashboard-icons-inline-svg.md new file mode 100644 index 0000000..c68f001 --- /dev/null +++ b/docs/decisions/0040-dashboard-icons-inline-svg.md @@ -0,0 +1,36 @@ +# 0040: Dashboard icons are inline stroke SVG in the page, not emoji + +- **Status:** Accepted +- **Date:** 2026-11-28 +- **Area:** Dashboard +- **Source:** Issue #217 +- **Supersedes:** — + +## Context + +The dashboard used emoji as icons. They render differently on every operating system and browser, cannot take a +palette colour and clash with the charts. The page must stay self-contained (`default-src 'self'`, `img-src 'self' +data:`, no inline style), embedded in the binary, small enough for a Pi Zero, and `app.js` must not build markup with +`innerHTML`. + +## Options considered + +1. **Inline `` at each use in `index.html`, drawn with `currentColor`; icons the script adds (the network + arrows) cloned from a ` PiMonitor - +
-

🖥️ PiMonitor

+ +
+

PiMonitor

Loading…
+
- - + +
@@ -30,7 +33,7 @@

🖥️ PiMonitor