Logout, reboot and shut down now fill with accent liquid while held and run once full; letting go early drains it. A tap hints to hold. Replaces the Confirm/Cancel rows in the control center tile and dashboard tab. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
153 lines
5.4 KiB
QML
153 lines
5.4 KiB
QML
pragma ComponentBehavior: Bound
|
|
import QtQuick
|
|
import QtQuick.Layouts
|
|
import Quickshell
|
|
import Quickshell.Io
|
|
import ".."
|
|
import "../../core"
|
|
import "../../services"
|
|
import "../../theme"
|
|
|
|
// Lock, restart and shut down. Restart and shut down are held to confirm:
|
|
// accent liquid fills the button, then the action runs.
|
|
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
|
|
// A tap on a hold button says to hold it, in place of the label.
|
|
property bool hint: false
|
|
spacing: 10
|
|
Timer {
|
|
id: hintTimer
|
|
interval: 1600
|
|
onTriggered: action.hint = false
|
|
}
|
|
DashButton {
|
|
objectName: "dashPower-" + action.modelData.id
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
size: 84
|
|
glyphScale: 0.36
|
|
glyph: action.modelData.glyph
|
|
fallback: action.modelData.fallback
|
|
hold: PowerService.needsHold(action.modelData.id)
|
|
armed: action.armed
|
|
interactive: root.available(action.modelData.id)
|
|
onClicked: root.run(action.modelData.id)
|
|
onPressedChanged: if (hold) {
|
|
if (pressed)
|
|
PowerService.request(action.modelData.id);
|
|
else if (action.armed)
|
|
PowerService.cancel();
|
|
}
|
|
onHeld: PowerService.confirm()
|
|
onHoldCancelled: {
|
|
action.hint = true;
|
|
hintTimer.restart();
|
|
}
|
|
Accessible.name: hold ? "Hold to " + action.modelData.label.toLowerCase() : action.modelData.label
|
|
}
|
|
Text {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
text: action.hint ? "Hold to " + action.modelData.label.toLowerCase() : action.modelData.label
|
|
color: action.armed ? Theme.text : Theme.textSecondary
|
|
font.pixelSize: 13
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|