From dab1b9b3897e682e13cf247bf5b43345bbe416ab Mon Sep 17 00:00:00 2001 From: quadbyte Date: Tue, 12 Aug 2025 10:17:39 -0400 Subject: [PATCH] ProfileCard: uptime is back --- Modules/SidePanel/ProfileCard.qml | 43 +++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/Modules/SidePanel/ProfileCard.qml b/Modules/SidePanel/ProfileCard.qml index 242a5a7..dac0715 100644 --- a/Modules/SidePanel/ProfileCard.qml +++ b/Modules/SidePanel/ProfileCard.qml @@ -1,7 +1,9 @@ import QtQuick +import QtQuick.Effects import QtQuick.Layouts import Quickshell -import QtQuick.Effects +import Quickshell.Io +import Quickshell.Widgets import qs.Services import qs.Widgets @@ -13,6 +15,8 @@ NBox { // Hold a single instance of the Settings window (root is NLoader) property var settingsWindow: null + property string uptimeText: "--" + Layout.fillWidth: true // Height driven by content implicitHeight: content.implicitHeight + Style.marginMedium * 2 * scaling @@ -42,7 +46,7 @@ NBox { font.weight: Style.fontWeightBold } NText { - text: "System Uptime: —" + text: `System Uptime: ${uptimeText}` color: Colors.textSecondary } } @@ -80,4 +84,39 @@ NBox { } } } + + + Timer { + interval: 60000 + repeat: true + running: true + onTriggered: uptimeProcess.running = true + } + + Process { + id: uptimeProcess + command: ["cat", "/proc/uptime"] + running: true + + stdout: StdioCollector { + onStreamFinished: { + var uptimeSeconds = parseFloat(this.text.trim().split(' ')[0]) + + var minutes = Math.floor(uptimeSeconds / 60) % 60 + var hours = Math.floor(uptimeSeconds / 3600) % 24 + var days = Math.floor(uptimeSeconds / 86400) + + // Format the output + if (days > 0) { + uptimeText = days + "d " + hours + "h" + } else if (hours > 0) { + uptimeText = hours + "h" + minutes + "m" + } else { + uptimeText = minutes + "m" + } + + uptimeProcess.running = false + } + } + } }