pragma ComponentBehavior: Bound import QtQuick import QtQuick.Layouts import Quickshell import Quickshell.Io import ".." import "../../components" import "../../core" import "../../services" import "../../theme" // Lock, restart and shut down. Restart and shut down ask for confirmation. Item { id: root property bool current: false implicitWidth: card.implicitWidth implicitHeight: card.implicitHeight onCurrentChanged: if (!current) PowerService.cancel() FileView { id: uptime path: "/proc/uptime" } Timer { interval: 60000 running: root.current repeat: true triggeredOnStart: true onTriggered: uptime.reload() } readonly property string uptimeText: { const seconds = parseFloat(uptime.text()); if (!Number.isFinite(seconds)) return ""; const d = Math.floor(seconds / 86400), h = Math.floor(seconds % 86400 / 3600), m = Math.floor(seconds % 3600 / 60); return "Up " + (d ? d + "d " : "") + (d || h ? h + "h " : "") + m + "m"; } readonly property var actions: [ { id: "lock", label: "Lock", glyph: "󰌾", fallback: "L" }, { id: "reboot", label: "Restart", glyph: "󰜉", fallback: "R" }, { id: "shutdown", label: "Shut down", glyph: "󰐥", fallback: "⏻" } ] function available(id) { if (id === "lock" && ConfigService.ready && ConfigService.data.lock.enabled) return true; return !!SystemService.state.power && !!SystemService.state.power[id] && !SystemService.acting; } function run(id) { if (id === "lock") ShellState.dashboardOpen = false; PowerService.request(id); } DashCard { id: card implicitWidth: 520 implicitHeight: body.implicitHeight + 48 ColumnLayout { id: body anchors.left: parent.left anchors.right: parent.right anchors.top: parent.top anchors.margins: 24 spacing: 20 ColumnLayout { Layout.fillWidth: true spacing: 2 Text { text: (Quickshell.env("USER") || "user") + "@" + hostname.text().trim() color: Theme.text font.pixelSize: 16 font.weight: Font.DemiBold FileView { id: hostname path: "/etc/hostname" } } Text { text: root.uptimeText color: Theme.textSecondary font.pixelSize: 12 } } Row { Layout.alignment: Qt.AlignHCenter Layout.topMargin: 4 spacing: 56 Repeater { model: root.actions Column { id: action required property var modelData readonly property bool armed: PowerService.pending === modelData.id spacing: 10 DashButton { objectName: "dashPower-" + action.modelData.id anchors.horizontalCenter: parent.horizontalCenter size: 84 glyphScale: 0.36 glyph: action.modelData.glyph fallback: action.modelData.fallback active: action.armed danger: action.modelData.id !== "lock" interactive: root.available(action.modelData.id) onClicked: root.run(action.modelData.id) Accessible.name: action.modelData.label } Text { anchors.horizontalCenter: parent.horizontalCenter text: action.modelData.label color: action.armed ? Theme.text : Theme.textSecondary font.pixelSize: 13 } } } } RowLayout { id: confirm Layout.fillWidth: true spacing: 8 readonly property var pending: root.actions.find(a => a.id === PowerService.pending) opacity: pending ? 1 : 0 visible: opacity > 0 Behavior on opacity { NumberAnimation { duration: Theme.duration } } Text { text: confirm.pending ? confirm.pending.label + " now? Unsaved work may be lost." : "" color: Theme.text font.pixelSize: 12 wrapMode: Text.Wrap Layout.fillWidth: true } GlassButton { objectName: "dashPowerCancel" text: "Cancel" onClicked: PowerService.cancel() } GlassButton { objectName: "dashPowerConfirm" text: confirm.pending ? confirm.pending.label : "Confirm" accented: true enabled: !SystemService.acting onClicked: PowerService.confirm() } } } } }