redesign nuguland power popup
61af1f01568a10c4c67145a96cefa6a5e3ac65e8
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
- Parent 1: 7ab8d4649702
bugabingas dorkfiles
61af1f01568a10c4c67145a96cefa6a5e3ac65e8
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
+533 / −0 text lines
new file mode 100644+134 / −0 text lines
# Nuguland Power Popup Implementation Plan> **For agentic workers:** REQUIRED SUB-SKILL: Use /skill:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.**Goal:** Implement the accepted two-zone Nuguland power popup from `docs/super/specs/2026-07-08-nuguland-power-popup-design.md`.**Architecture:** Keep session routing in `Power.qml`/`power.js`; change visual hierarchy in `PowerPanel.qml`. Add one pure `hasMainBattery()` helper so desktops do not render fake `0% unknown` battery heroes.**Tech Stack:** QML/QtQuick, Quickshell, Node `assert` tests for pure JavaScript shaping.**Roadmap:** None**Phase:** Single-plan implementation---### Task 1: Battery presence shaping**Files:**- Modify: `quickshell/nuguland/power.test.js`- Modify: `quickshell/nuguland/power.js`- Modify: `quickshell/nuguland/Power.qml`- [x] **Step 1: Write the failing test**Add assertions to `quickshell/nuguland/power.test.js` before the routing-table section:```js// --- hasMainBattery --------------------------------------------------------eq(P.hasMainBattery({ percent: 0, state: 'unknown', timeEstimate: 'unknown', health: -1 }), false, 'desktop display device placeholder is not a main battery');eq(P.hasMainBattery({ percent: 72, state: 'charging', timeEstimate: '1h', health: 91 }), true, 'real laptop battery is a main battery');eq(P.hasMainBattery({ percent: 0, state: 'discharging', timeEstimate: 'unknown', health: -1 }), true, 'reported discharging state is a main battery even at zero percent');```- [x] **Step 2: Run test to verify it fails**Run:```shcd quickshell/nuguland && node power.test.js```Expected: FAIL with `TypeError: P.hasMainBattery is not a function`.- [x] **Step 3: Implement minimal helper and export**Add to `quickshell/nuguland/power.js` near battery helpers:```jsfunction hasMainBattery(battery) { var b = battery || {}; var state = cleanState(b.state); return Number(b.percent || 0) > 0 || state !== 'unknown' || String(b.timeEstimate || 'unknown') !== 'unknown' || Number(b.health || -1) >= 0;}```Export it in `module.exports`.- [x] **Step 4: Mark native battery objects**In `Power.qml`, set `b.present = Power.hasMainBattery(b);` inside `batteryObject()` before assigning `role`.- [x] **Step 5: Run test to verify it passes**Run:```shcd quickshell/nuguland && node power.test.js```Expected: `power.test.js: ALL PASS`.### Task 2: Two-zone panel layout**Files:**- Modify: `quickshell/nuguland/PowerPanel.qml`- [x] **Step 1: Replace the old equal-weight layout**Rewrite `PowerPanel.qml` to keep existing service functions and key behavior, but render:- optional circular battery hero when `battery.present` is true;- compact external device chips;- one safe-action grid with `lock`, `suspend`, `monitor-off`, `monitor-on` filtered from `sessionActions`;- one danger region with `logout`, `reboot`, `poweroff` filtered from `sessionActions`;- confirmation card replacing the danger action grid while `pendingConfirmation` is set.- [x] **Step 2: Run formatter**Run:```shcd quickshell/nuguland && just fmt```Expected: command exits 0.### Task 3: Verification**Files:**- Verify: `quickshell/nuguland/power.test.js`- Verify: `quickshell/nuguland/PowerPanel.qml`- [x] **Step 1: Run pure tests**Run:```shcd quickshell/nuguland && node power.test.js```Expected: `power.test.js: ALL PASS`.- [x] **Step 2: Run Nuguland lint gate**Run:```shcd quickshell/nuguland && just lint```Expected: command exits 0 with no warnings.- [x] **Step 3: Commit focused changes**Run:```shgit add docs/super/plans/2026-07-08-nuguland-power-popup.md quickshell/nuguland/power.test.js quickshell/nuguland/power.js quickshell/nuguland/Power.qml quickshell/nuguland/PowerPanel.qmlgit commit -m "redesign nuguland power popup"```+1 / −0 text lines
new file mode 100644+386 / −0 text lines
pragma ComponentBehavior: Boundimport QtQuickimport "Util.js" as UtilColumn { id: root required property Theme theme required property Power powerService property var panelState: powerService ? Util.parseJson(powerService.stateJson(), { "battery": {}, "externalDevices": [] }) : ({ "battery": {}, "externalDevices": [] }) readonly property var battery: panelState.battery || ({}) readonly property var devices: panelState.externalDevices || [] readonly property var sessionActions: panelState.sessionActions || ["lock", "suspend", "monitor-off", "monitor-on", "logout", "reboot", "poweroff"] readonly property bool hasMainBattery: !!(battery && battery.present) readonly property var safeActionNames: ["lock", "suspend", "monitor-off", "monitor-on"] readonly property var destructiveActionNames: ["logout", "reboot", "poweroff"] readonly property var safeActions: actionSubset(safeActionNames) readonly property var destructiveActions: actionSubset(destructiveActionNames) function refreshFrom(text) { panelState = Util.parseJson(text, panelState); } function runSession(action) { if (powerService) refreshFrom(powerService.sessionAction(action)); } function confirm(action) { if (powerService) refreshFrom(powerService.confirmAction(action)); } function cancel() { if (powerService) refreshFrom(powerService.cancelAction()); } function roleColor(role) { if (!theme) return "white"; if (role === "warning") return theme.warning; if (role === "error") return theme.error; if (role === "ui.minor") return theme.ui.minor; return theme.ui.accent; } function actionSubset(names) { const rows = []; for (let i = 0; i < names.length; i++) { if (sessionActions.indexOf(names[i]) >= 0) rows.push(names[i]); } return rows; } function actionLabel(action) { if (action === "monitor-off") return "display off"; if (action === "monitor-on") return "display on"; if (action === "poweroff") return "power off"; return action; } function batteryMeta() { const parts = []; if (battery.timeEstimate && battery.timeEstimate !== "unknown") parts.push(battery.timeEstimate); if (battery.health >= 0) parts.push(`health ${battery.health}%`); return parts.join(" · "); } spacing: 12 width: parent ? parent.width : 0 focus: true Keys.onEscapePressed: root.cancel() Keys.onReturnPressed: root.panelState.pendingConfirmation ? root.confirm(root.panelState.pendingConfirmation) : root.runSession("lock") Keys.onEnterPressed: root.panelState.pendingConfirmation ? root.confirm(root.panelState.pendingConfirmation) : root.runSession("lock") Rectangle { objectName: "batteryHero" width: parent.width height: root.hasMainBattery ? 116 : 0 radius: 18 visible: root.hasMainBattery color: root.theme ? root.theme.withAlpha(root.theme.ui.backdrop, 0.56) : "transparent" border.width: 1 border.color: root.theme ? root.theme.withAlpha(root.roleColor(root.battery.role || "ui.accent"), 0.65) : "transparent" Rectangle { id: batteryDial anchors.left: parent.left anchors.leftMargin: 12 anchors.verticalCenter: parent.verticalCenter width: 92 height: 92 radius: 46 color: root.theme ? root.theme.withAlpha(root.roleColor(root.battery.role || "ui.accent"), 0.18) : "transparent" border.width: 1 border.color: root.theme ? root.roleColor(root.battery.role || "ui.accent") : "transparent" NuguText { anchors.centerIn: parent theme: root.theme variant: "title" font.pixelSize: 25 text: `${root.battery.percent || 0}%` color: root.theme ? root.theme.content.normal : "white" } } Column { anchors.left: batteryDial.right anchors.leftMargin: 14 anchors.right: parent.right anchors.rightMargin: 14 anchors.verticalCenter: parent.verticalCenter spacing: 8 NuguText { theme: root.theme variant: "title" width: parent.width text: root.battery.state || "unknown" color: root.theme ? root.roleColor(root.battery.role || "ui.accent") : "white" elide: Text.ElideRight } NuguText { theme: root.theme variant: "meta" width: parent.width visible: root.batteryMeta().length > 0 text: root.batteryMeta() color: root.theme ? root.theme.ui.minor : "white" elide: Text.ElideRight } } } Flow { id: deviceFlow objectName: "externalDeviceBatteryChips" width: parent.width height: visible ? implicitHeight : 0 spacing: 8 visible: root.devices.length > 0 Repeater { model: root.devices delegate: Rectangle { id: deviceChip required property var modelData width: Math.floor((root.width - 8) / 2) height: 32 radius: 11 color: root.theme ? root.theme.withAlpha(root.theme.ui.backdrop, 0.55) : "transparent" border.width: 1 border.color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.42) : "transparent" NuguText { anchors.left: parent.left anchors.leftMargin: 9 anchors.right: devicePercent.left anchors.rightMargin: 8 anchors.verticalCenter: parent.verticalCenter theme: root.theme variant: "meta" text: `${deviceChip.modelData.name}` color: root.theme ? root.theme.ui.minor : "white" elide: Text.ElideRight } NuguText { id: devicePercent anchors.right: parent.right anchors.rightMargin: 9 anchors.verticalCenter: parent.verticalCenter theme: root.theme variant: "meta" selected: true text: `${deviceChip.modelData.percent}%` } } } } Grid { id: safeGrid objectName: "safeActionGrid" width: parent.width columns: 2 columnSpacing: 8 rowSpacing: 8 Repeater { model: root.safeActions delegate: Rectangle { id: safeButton required property string modelData readonly property bool primary: modelData === "lock" width: Math.floor((root.width - safeGrid.columnSpacing) / safeGrid.columns) height: 42 radius: 13 color: root.theme ? root.theme.withAlpha(primary ? root.theme.ui.accent : root.theme.ui.backdrop, primary ? 0.26 : 0.56) : "transparent" border.width: primary ? 1 : 0 border.color: root.theme ? (primary ? root.theme.ui.accent : "transparent") : "transparent" NuguText { anchors.centerIn: parent theme: root.theme variant: "meta" selected: safeButton.primary text: root.actionLabel(safeButton.modelData) color: root.theme ? (safeButton.primary ? root.theme.ui.accent : root.theme.content.normal) : "white" } MouseArea { anchors.fill: parent hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: root.runSession(safeButton.modelData) } } } } Rectangle { objectName: "dangerRegion" width: parent.width height: root.panelState.pendingConfirmation ? 62 : 58 radius: 18 color: root.theme ? root.theme.withAlpha(root.panelState.pendingConfirmation ? root.theme.warning : root.theme.error, root.panelState.pendingConfirmation ? 0.12 : 0.08) : "transparent" border.width: 1 border.color: root.theme ? root.theme.withAlpha(root.panelState.pendingConfirmation ? root.theme.warning : root.theme.error, 0.62) : "transparent" Grid { id: dangerGrid anchors.fill: parent anchors.margins: 10 columns: 3 columnSpacing: 8 visible: !root.panelState.pendingConfirmation Repeater { model: root.destructiveActions delegate: Rectangle { id: dangerButton required property string modelData width: Math.floor((dangerGrid.width - dangerGrid.columnSpacing * 2) / 3) height: 38 radius: 12 color: root.theme ? root.theme.withAlpha(root.theme.error, dangerArea.containsMouse ? 0.2 : 0.12) : "transparent" border.width: 1 border.color: root.theme ? root.theme.withAlpha(root.theme.error, 0.5) : "transparent" NuguText { anchors.centerIn: parent theme: root.theme variant: "meta" text: root.actionLabel(dangerButton.modelData) color: root.theme ? root.theme.error : "white" } MouseArea { id: dangerArea anchors.fill: parent hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: root.runSession(dangerButton.modelData) } } } } Row { anchors.fill: parent anchors.margins: 10 spacing: 8 visible: !!root.panelState.pendingConfirmation NuguText { anchors.verticalCenter: parent.verticalCenter theme: root.theme variant: "title" text: root.actionLabel(root.panelState.pendingConfirmation) color: root.theme ? root.theme.warning : "white" width: parent.width - confirmButton.width - cancelButton.width - 16 elide: Text.ElideRight } Rectangle { id: confirmButton anchors.verticalCenter: parent.verticalCenter width: 82 height: 38 radius: 12 color: root.theme ? root.theme.withAlpha(root.theme.warning, confirmArea.containsMouse ? 0.28 : 0.18) : "transparent" border.width: 1 border.color: root.theme ? root.theme.warning : "transparent" NuguText { anchors.centerIn: parent theme: root.theme variant: "meta" selected: true text: "confirm" color: root.theme ? root.theme.warning : "white" } MouseArea { id: confirmArea anchors.fill: parent hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: root.confirm(root.panelState.pendingConfirmation) } } Rectangle { id: cancelButton anchors.verticalCenter: parent.verticalCenter width: 74 height: 38 radius: 12 color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, cancelArea.containsMouse ? 0.18 : 0.1) : "transparent" border.width: 0 border.color: "transparent" NuguText { anchors.centerIn: parent theme: root.theme variant: "meta" text: "cancel" color: root.theme ? root.theme.content.normal : "white" } MouseArea { id: cancelArea anchors.fill: parent hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: root.cancel() } } } }}+7 / −0 text lines
hasMainBattery: hasMainBattery,+5 / −0 text lines
// --- hasMainBattery --------------------------------------------------------eq(P.hasMainBattery({ percent: 0, state: 'unknown', timeEstimate: 'unknown', health: -1 }), false, 'desktop display device placeholder is not a main battery');eq(P.hasMainBattery({ percent: 72, state: 'charging', timeEstimate: '1h', health: 91 }), true, 'real laptop battery is a main battery');eq(P.hasMainBattery({ percent: 0, state: 'discharging', timeEstimate: 'unknown', health: -1 }), true, 'reported discharging state is a main battery even at zero percent');