nova-shell/modules/Memory.qml

46 lines
1.1 KiB
QML

import QtQuick
import Quickshell.Io
import "." as M
M.BarSection {
id: root
spacing: Math.max(1, M.Theme.moduleSpacing - 2)
tooltip: "Memory: " + root.percent + "% used"
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: M.Modules.memory.interval || 2000
running: true
repeat: true
onTriggered: meminfo.reload()
}
M.BarIcon {
icon: "\uEFC5"
anchors.verticalCenter: parent.verticalCenter
}
M.BarLabel {
label: root.percent + "%"
minText: "100%"
anchors.verticalCenter: parent.verticalCenter
}
}