1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-31 00:42:50 -05:00

fix(uptime): replace 'uptime -p' with /proc/uptime parsing

On NixOS, the default `uptime` command from coreutils does not support
the `-p` option.
This replaces the previous `bash`-based solution with a call to
`/proc/uptime`,
and parses the result in JavaScript to produce a human-readable format
like:

    "up 1 day, 2 hours, 5 minutes"

This makes uptime reporting fully compatible with NixOS and more
portable.
This commit is contained in:
loner
2025-08-06 11:01:42 +08:00
parent 7e21453533
commit 4d2a65dc7e

View File

@@ -66,20 +66,35 @@ Singleton {
Process { Process {
id: uptimeProcess id: uptimeProcess
command: ["bash", "-c", "uptime -p | sed 's/up //'"] command: ["cat", "/proc/uptime"]
running: false running: false
onExited: (exitCode) => { onExited: (exitCode) => {
if (exitCode !== 0) { if (exitCode !== 0) {
root.uptime = "Unknown"; root.uptime = "Unknown";
} }
} }
stdout: StdioCollector { stdout: StdioCollector {
onStreamFinished: { onStreamFinished: {
root.uptime = text.trim() || "Unknown"; const seconds = parseInt(text.split(" ")[0]);
} const days = Math.floor(seconds / 86400);
} const hours = Math.floor((seconds % 86400) / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
const parts = [];
if (days > 0)
parts.push(`${days} day${days === 1 ? "" : "s"}`);
if (hours > 0)
parts.push(`${hours} hour${hours === 1 ? "" : "s"}`);
if (minutes > 0)
parts.push(`${minutes} minute${minutes === 1 ? "" : "s"}`);
if (parts.length > 0)
root.uptime = "up " + parts.join(", ");
else
root.uptime = `up ${seconds} seconds`;
}
}
} }
} }