pragma Singleton import QtQuick import Quickshell import ZShell.Internal import ZShell.Services Singleton { id: root readonly property int historyLength: 30 readonly property CircularBuffer cpuBuffer: _cpuBuffer readonly property CircularBuffer memoryBuffer: _memoryBuffer readonly property list cpuInfo: [ { label: qsTr("Usage"), value: `${Math.round(Cpu.percentage * 100)}%` }, { label: qsTr("Temp"), value: `${Math.ceil(Cpu.temperature)}°${"C"}` } ] readonly property list memoryInfo: [ { label: qsTr("Used"), value: memoryUsageFormat(Memory.used, Memory.total) }, { label: qsTr("Cached"), value: memoryTotalFormat(Memory.cached) }, { label: qsTr("Writes"), value: memoryTotalFormat(Memory.writeTotal) }, { label: qsTr("Reads"), value: memoryTotalFormat(Memory.readTotal) } ] function memoryTotalFormat(kib: int): string { const fmt = UsageFmt.formatKib(kib); return `${fmt.value.toFixed(1)} ${fmt.unit}`; } function memoryUsageFormat(used: int, total: int): string { const fmt = UsageFmt.formatKib(used, total); return `${fmt.value.toFixed(1)} / ${Math.floor(fmt.total)} ${fmt.unit}`; } Connections { function onUpdateTriggered(): void { if (Cpu.percentage >= 0 && isFinite(Cpu.percentage)) _cpuBuffer.push(Cpu.percentage); } target: Cpu } Connections { function onUpdateTriggered(): void { if (Memory.percentage >= 0 && isFinite(Memory.percentage)) _memoryBuffer.push(Memory.percentage); } target: Memory } CircularBuffer { id: _cpuBuffer capacity: root.historyLength + 1 smoothingRadius: 2 } CircularBuffer { id: _memoryBuffer capacity: root.historyLength + 1 smoothingRadius: 2 } }