ProfileCard: uptime is back
This commit is contained in:
parent
0202965f65
commit
dab1b9b389
1 changed files with 41 additions and 2 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue