nova-shell/modules/Memory.qml
2026-04-11 00:22:09 +02:00

38 lines
897 B
QML

import QtQuick
import Quickshell.Io
import "." as M
Text {
id: root
property int percent: 0
FileView {
id: meminfo
path: "/proc/meminfo"
onLoaded: {
const m = {};
text().split("\n").forEach(l => {
const [k, v] = l.split(":");
if (v)
m[k.trim()] = parseInt(v.trim());
});
const total = m.MemTotal;
const avail = m.MemAvailable;
if (total > 0)
root.percent = Math.round(((total - avail) / total) * 100);
}
}
Timer {
interval: 2000
running: true
repeat: true
onTriggered: meminfo.reload()
}
text: " " + root.percent + "%"
color: M.Theme.base05
font.pixelSize: M.Theme.fontSize
font.family: M.Theme.fontFamily
verticalAlignment: Text.AlignVCenter
}