fix: column index desync after reorder
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
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<var> cpuInfo: [
|
||||
{
|
||||
label: qsTr("Usage"),
|
||||
value: `${Math.round(Cpu.percentage * 100)}%`
|
||||
},
|
||||
{
|
||||
label: qsTr("Temp"),
|
||||
value: `${Math.ceil(Cpu.temperature)}°${"C"}`
|
||||
}
|
||||
]
|
||||
|
||||
readonly property list<var> 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user