1 +#
Power popup redesign — design 3 +Popup 4 of 4 in the nuguland popup redesign sweep (audio → brightness →
4 +network → **power**). Same architecture as the prior three: a pure,
5 +node-tested `.js` module + a thin QML service that owns native objects + a
10 +Make the power popup honest and lean: real session actions, real battery
11 +status, no fake features, no dead code, washout-fixed cards.
13 +##
What was wrong (recon) 15 +- **Fake session actions.** `executeSessionAction` only handled
16 + lock/monitor-off/monitor-on. `suspend`, `logout`, `reboot`, `poweroff`
17 + were advertised in the grid but executed **nothing** (destructive ones got
18 + a confirm prompt, then a silent no-op).
19 +- **Fake power-profile selector.** `setProfile` only set a local
20 + `selectedProfile` string; no daemon write. This host has no
21 + power-profiles-daemon at all (`org.freedesktop.UPower.PowerProfiles … not
23 +- **Dead code.** `powerHistorySamples` grew every 2s via a `Timer` toward
24 + 3599 entries with no renderer; a `power-gradient` shader descriptor pointed
25 + at a `.qsb` file that does not exist.
26 +- **Narration.** `powerPanelContract`, `backend`, `usesUPower`,
27 + `nativeActionRoute`, `helperProcesses`, `boundedActions`,
28 + `lowPowerPolicy` — self-describing JSON nothing consumed.
32 +- **Session actions → real.** Routing table in `power.js#actionPlan`:
33 + - `lock` → `lockService.request()`
34 + - `monitor-off/on` → `niriService.action(["power-off-monitors" | "power-on-monitors"])`
35 + - `logout` → `niriService.action(["quit", "--skip-confirmation"])` (popup
36 + already two-step confirms, so skip niri's own Enter prompt)
37 + - `suspend` → `Quickshell.execDetached(["systemctl", "suspend"])`
38 + - `reboot` → `["systemctl", "reboot"]`
39 + - `poweroff` → `["systemctl", "poweroff"]`
40 + - argv/args are discrete token arrays — never a shell string, no injection
41 + surface. logind polkit allows the active session to run these without
43 +- **Confirm gating.** `logout`/`reboot`/`poweroff` are two-step
44 + (`requiresConfirmation`); `suspend` is recoverable so it fires
45 + immediately; `lock`/monitor are immediate.
46 +- **Profile selector → deleted.** Quickshell's `PowerProfiles` exposes no
47 + clean "daemon available" property (only `hasPerformanceProfile`, which is
48 + wrong for a balanced-only ppd host). On this host there is no ppd at all,
49 + so an always-shown selector would silently no-op — the same dishonesty
50 + being removed. Cut whole, per the standing "less code / no fake features"
51 + directive. Revisit if the host adopts ppd.
52 +- **`lowPowerMode()` kept** — load-bearing: `shell.qml` binds
53 + `nuguTheme.lowPowerMode` to it, which gates every animation across the UI.
57 +`power.js` (pure, dual-mode export, `node power.test.js` → ALL PASS):
58 +`normalizePercent`, `minutesToLabel`, `cleanState`, `batteryRole`,
59 +`timeEstimateLabel`, `isLowPower`, `SESSION_ACTIONS`, `DESTRUCTIVE_ACTIONS`,
60 +`requiresConfirmation`, `actionPlan`, `actionLabel`.
62 +`Power.qml` (native): UPower `displayDevice`/`devices` reads,
63 +`UPowerDeviceState`/`Type` enums, the action sink (`runPlan`), the confirm
64 +state machine, `lowPowerMode()`, `selfTest()`.
66 +##
State (IPC contract) 68 +`stateJson()` → `{ battery{id,percent,state,timeEstimate,health,role},
69 +externalDevices[], sessionActions[], destructiveActions[],
70 +compact{label,role,charging}, pendingConfirmation, lastAction }`.
71 +IPC handlers: `powerState`, `powerSessionAction`, `powerConfirmAction`,
72 +`powerCancelAction`, `powerSelfTest` (replaced `powerSetProfile`).
74 +##
View (PopoutHost PowerPanel) 76 +Battery hero + external-device rows + 4-col action grid + confirm strip.
77 +Washout fix (popup frame is light): cards use a solid
78 +`withAlpha(ui.backdrop, 0.55)` base (0.82 when pending) with the role colour
79 +on the **border**, never the fill. Destructive actions carry an `error`
80 +border; pending carries a thicker `warning` border.
84 +`node power.test.js` (50 assertions) → clear qmlcache → restart →
85 +journal clean → `powerSelfTest` `{ok:true,9/9}` → `powerState` real battery
86 +→ open popout + screenshot. **Destructive actions verified by gating only**
87 +(`powerSessionAction poweroff` sets `pendingConfirmation` and returns
88 +`confirmed:false`; the action is never fired during verification).