extract constants

This commit is contained in:
Damocles 2026-04-12 10:57:48 +02:00
parent bc3a85d18d
commit b969f0824f
22 changed files with 106 additions and 63 deletions

View file

@ -4,7 +4,7 @@ import "." as M
M.BarSection {
id: root
spacing: 2
spacing: Math.max(1, M.Theme.moduleSpacing - 2)
tooltip: "CPU: " + root.usage + "%\n" + root.freqGhz.toFixed(2) + " GHz"
property int usage: 0
@ -25,7 +25,10 @@ M.BarSection {
if (dTotal > 0)
root.usage = Math.round((1 - dIdle / dTotal) * 100);
}
root._prev = { idle, total };
root._prev = {
idle,
total
};
}
}
FileView {
@ -33,7 +36,8 @@ M.BarSection {
path: "/proc/cpuinfo"
onLoaded: {
const lines = text().split("\n").filter(l => l.startsWith("cpu MHz"));
if (lines.length === 0) return;
if (lines.length === 0)
return;
const sum = lines.reduce((a, l) => a + parseFloat(l.split(":")[1]), 0);
root.freqGhz = sum / lines.length / 1000;
}
@ -42,7 +46,10 @@ M.BarSection {
interval: 1000
running: true
repeat: true
onTriggered: { stat.reload(); cpuinfo.reload(); }
onTriggered: {
stat.reload();
cpuinfo.reload();
}
}
M.BarIcon {