dashboard: use file uptime

This commit is contained in:
2 * r + 2 * t 2025-07-12 16:58:10 +10:00
parent 1bd92b4740
commit e9268415a1

View file

@ -126,26 +126,38 @@ Row {
} }
InfoLine { InfoLine {
id: uptime
icon: "timer" icon: "timer"
text: uptimeProc.uptime text: qsTr("Loading uptime...")
colour: Colours.palette.m3tertiary colour: Colours.palette.m3tertiary
Timer { Timer {
running: true running: true
repeat: true repeat: true
interval: 15000 interval: 15000
onTriggered: uptimeProc.running = true onTriggered: fileUptime.reload()
} }
Process { FileView {
id: uptimeProc id: fileUptime
property string uptime path: "/proc/uptime"
onLoaded: {
const up = parseInt(text().split(" ")[0] ?? 0);
running: true const days = Math.floor(up / 86400);
command: ["uptime", "-p"] const hours = Math.floor((up % 86400) / 3600);
stdout: StdioCollector { const minutes = Math.floor((up % 3600) / 60);
onStreamFinished: uptimeProc.uptime = text.trim()
let str = qsTr("up ");
if (days > 0)
str += `${days} day${days === 1 ? "" : "s"}`;
if (hours > 0)
str += `${str ? ", " : ""}${hours} hour${hours === 1 ? "" : "s"}`;
if (minutes > 0 || !str)
str += `${str ? ", " : ""}${minutes} minute${minutes === 1 ? "" : "s"}`;
uptime.text = str;
} }
} }
} }