43 lines
1.2 KiB
QML
43 lines
1.2 KiB
QML
import QtQuick
|
|
import Quickshell.Io
|
|
|
|
QtObject {
|
|
id: root
|
|
|
|
property string sortBy: "cpu" // "cpu" or "mem"
|
|
property int maxItems: 8
|
|
property bool active: false
|
|
|
|
property var processes: []
|
|
|
|
property Process _proc: Process {
|
|
command: ["sh", "-c", "ps --no-headers -eo pid,pcpu,pmem,comm --sort=-%" + root.sortBy + " | head -" + root.maxItems]
|
|
stdout: StdioCollector {
|
|
onStreamFinished: {
|
|
const rows = [];
|
|
for (const line of text.trim().split("\n")) {
|
|
if (!line)
|
|
continue;
|
|
const p = line.trim().split(/\s+/);
|
|
if (p.length < 4)
|
|
continue;
|
|
rows.push({
|
|
"pid": parseInt(p[0]),
|
|
"cpu": parseFloat(p[1]),
|
|
"mem": parseFloat(p[2]),
|
|
"cmd": p.slice(3).join(" ")
|
|
});
|
|
}
|
|
root.processes = rows;
|
|
}
|
|
}
|
|
}
|
|
|
|
property Timer _timer: Timer {
|
|
interval: 2000
|
|
running: root.active
|
|
repeat: true
|
|
triggeredOnStart: true
|
|
onTriggered: root._proc.running = true
|
|
}
|
|
}
|