summaryrefslogtreecommitdiff
path: root/services/NetworkUsage.qml
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2026-03-12 22:51:07 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2026-03-12 22:51:07 +1100
commit27cb290423ba5c30c1856427609938c230fa9f32 (patch)
tree037e5ede085be567b0dec680eb7a10cb423682bd /services/NetworkUsage.qml
parentnotifs: skip markdown parsing for plain text bodies (diff)
downloadcaelestia-shell-27cb290423ba5c30c1856427609938c230fa9f32.tar.gz
caelestia-shell-27cb290423ba5c30c1856427609938c230fa9f32.tar.bz2
caelestia-shell-27cb290423ba5c30c1856427609938c230fa9f32.zip
feat: replace canvas -> c++ component
Also add c++ ring buffer
Diffstat (limited to 'services/NetworkUsage.qml')
-rw-r--r--services/NetworkUsage.qml34
1 files changed, 19 insertions, 15 deletions
diff --git a/services/NetworkUsage.qml b/services/NetworkUsage.qml
index a940648..4518647 100644
--- a/services/NetworkUsage.qml
+++ b/services/NetworkUsage.qml
@@ -5,6 +5,8 @@ import qs.config
import Quickshell
import Quickshell.Io
+import Caelestia.Internal
+
import QtQuick
Singleton {
@@ -20,9 +22,9 @@ Singleton {
readonly property real downloadTotal: _downloadTotal
readonly property real uploadTotal: _uploadTotal
- // History of speeds for sparkline (most recent at end)
- readonly property var downloadHistory: _downloadHistory
- readonly property var uploadHistory: _uploadHistory
+ // History buffers for sparkline
+ readonly property CircularBuffer downloadBuffer: _downloadBuffer
+ readonly property CircularBuffer uploadBuffer: _uploadBuffer
readonly property int historyLength: 30
// Private properties
@@ -30,8 +32,6 @@ Singleton {
property real _uploadSpeed: 0
property real _downloadTotal: 0
property real _uploadTotal: 0
- property var _downloadHistory: []
- property var _uploadHistory: []
// Previous readings for calculating speed
property real _prevRxBytes: 0
@@ -139,6 +139,16 @@ Singleton {
};
}
+ CircularBuffer {
+ id: _downloadBuffer
+ capacity: root.historyLength + 1
+ }
+
+ CircularBuffer {
+ id: _uploadBuffer
+ capacity: root.historyLength + 1
+ }
+
FileView {
id: netDevFile
path: "/proc/net/dev"
@@ -189,17 +199,11 @@ Singleton {
root._downloadSpeed = rxDelta / timeDelta;
root._uploadSpeed = txDelta / timeDelta;
- const maxHistory = root.historyLength + 1;
-
- if (root._downloadSpeed >= 0 && isFinite(root._downloadSpeed)) {
- const dh = root._downloadHistory;
- root._downloadHistory = dh.length >= maxHistory ? [...dh.slice(1), root._downloadSpeed] : [...dh, root._downloadSpeed];
- }
+ if (root._downloadSpeed >= 0 && isFinite(root._downloadSpeed))
+ _downloadBuffer.push(root._downloadSpeed);
- if (root._uploadSpeed >= 0 && isFinite(root._uploadSpeed)) {
- const uh = root._uploadHistory;
- root._uploadHistory = uh.length >= maxHistory ? [...uh.slice(1), root._uploadSpeed] : [...uh, root._uploadSpeed];
- }
+ if (root._uploadSpeed >= 0 && isFinite(root._uploadSpeed))
+ _uploadBuffer.push(root._uploadSpeed);
}
// Calculate totals with overflow handling