1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-09 23:15:38 -05:00

Merge pull request #11 from lonerOrz/uptime

fix(uptime): replace 'uptime -p' with /proc/uptime parsing
This commit is contained in:
BB
2025-08-05 23:41:49 -04:00
committed by GitHub

View File

@@ -41,7 +41,7 @@ Singleton {
running: false running: false
onExited: (exitCode) => { onExited: (exitCode) => {
if (exitCode !== 0) { if (exitCode !== 0) {
root.username = "User"; root.username = "User";
root.fullName = "User"; root.fullName = "User";
root.hostname = "System"; root.hostname = "System";
@@ -55,7 +55,7 @@ Singleton {
root.username = parts[0] || ""; root.username = parts[0] || "";
root.fullName = parts[1] || parts[0] || ""; root.fullName = parts[1] || parts[0] || "";
root.hostname = parts[2] || ""; root.hostname = parts[2] || "";
} }
} }
} }
@@ -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`;
} }
} }
}
}
} }