diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-07-12 16:58:10 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-07-12 16:58:10 +1000 |
| commit | e9268415a1e83b65f8e2f61e74fe1a3ef4cef082 (patch) | |
| tree | 5636f362bd1cdb661bd8cc013b2a53716691d48a /modules/dashboard/dash/User.qml | |
| parent | bar: some internal fixes (diff) | |
| download | caelestia-shell-e9268415a1e83b65f8e2f61e74fe1a3ef4cef082.tar.gz caelestia-shell-e9268415a1e83b65f8e2f61e74fe1a3ef4cef082.tar.bz2 caelestia-shell-e9268415a1e83b65f8e2f61e74fe1a3ef4cef082.zip | |
dashboard: use file uptime
Diffstat (limited to 'modules/dashboard/dash/User.qml')
| -rw-r--r-- | modules/dashboard/dash/User.qml | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/modules/dashboard/dash/User.qml b/modules/dashboard/dash/User.qml index 403885f..b224d17 100644 --- a/modules/dashboard/dash/User.qml +++ b/modules/dashboard/dash/User.qml @@ -126,26 +126,38 @@ Row { } InfoLine { + id: uptime + icon: "timer" - text: uptimeProc.uptime + text: qsTr("Loading uptime...") colour: Colours.palette.m3tertiary Timer { running: true repeat: true interval: 15000 - onTriggered: uptimeProc.running = true + onTriggered: fileUptime.reload() } - Process { - id: uptimeProc + FileView { + id: fileUptime - property string uptime + path: "/proc/uptime" + onLoaded: { + const up = parseInt(text().split(" ")[0] ?? 0); - running: true - command: ["uptime", "-p"] - stdout: StdioCollector { - onStreamFinished: uptimeProc.uptime = text.trim() + const days = Math.floor(up / 86400); + const hours = Math.floor((up % 86400) / 3600); + const minutes = Math.floor((up % 3600) / 60); + + 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; } } } |