aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/modules')
-rw-r--r--desktop/modules/network/NetworkModule.qml60
-rw-r--r--desktop/modules/network/NetworkPage.qml147
2 files changed, 154 insertions, 53 deletions
diff --git a/desktop/modules/network/NetworkModule.qml b/desktop/modules/network/NetworkModule.qml
index 0310475..186d15b 100644
--- a/desktop/modules/network/NetworkModule.qml
+++ b/desktop/modules/network/NetworkModule.qml
@@ -104,6 +104,66 @@ Module {
property Process notifyProc: Process {}
+ // Ookla's CLI, run on demand. It lives here rather than in the page so a
+ // test survives the drawer closing and its result is still there on
+ // reopen. --format=jsonl streams one event per line: testStart, then
+ // ping, download and upload events carrying `progress` (0..1) and the
+ // running `bandwidth` (bytes/s), then one result (measured: 5 ping, 72
+ // download, 104 upload events on a gigabit line).
+ property var speedResult: null // {down, up, ping, server} or null
+ property string speedPhase: "" // ping | download | upload while running
+ property real speedProgress: 0
+ property real speedLive: 0 // Mbit/s, the current phase's running figure
+ property var speedDown: [] // Mbit/s samples, for the page's graph
+ property var speedUp: []
+ readonly property bool speedRunning: speedProc.running
+ function runSpeedtest() {
+ mod.speedResult = null;
+ mod.speedPhase = "";
+ mod.speedProgress = 0;
+ mod.speedLive = 0;
+ mod.speedDown = [];
+ mod.speedUp = [];
+ mod.error = "";
+ speedProc.running = false;
+ speedProc.running = true;
+ }
+
+ property Process speedProc: Process {
+ command: [Quickshell.env("HOME") + "/bin/speedtest", "--format=jsonl",
+ "--accept-license", "--accept-gdpr"]
+ stdout: SplitParser {
+ onRead: line => {
+ let r;
+ try { r = JSON.parse(line); } catch (e) { return; }
+ const ev = r[r.type];
+ if (r.type === "ping") {
+ mod.speedPhase = "ping";
+ mod.speedProgress = ev.progress;
+ mod.speedLive = 0;
+ } else if (r.type === "download" || r.type === "upload") {
+ const mbit = ev.bandwidth * 8 / 1e6;
+ mod.speedPhase = r.type;
+ mod.speedProgress = ev.progress;
+ mod.speedLive = mbit;
+ if (r.type === "download") mod.speedDown = mod.speedDown.concat([mbit]);
+ else mod.speedUp = mod.speedUp.concat([mbit]);
+ } else if (r.type === "result") {
+ mod.speedResult = {
+ down: r.download.bandwidth * 8 / 1e6,
+ up: r.upload.bandwidth * 8 / 1e6,
+ ping: r.ping.latency,
+ server: r.server.name + ", " + r.server.location
+ };
+ }
+ }
+ }
+ onExited: code => {
+ mod.speedPhase = "";
+ if (!mod.speedResult) mod.error = "Speedtest failed (exit " + code + ")";
+ }
+ }
+
property Process ipProc: Process {
command: ["ip", "-j", "-4", "addr", "show"]
stdout: StdioCollector {
diff --git a/desktop/modules/network/NetworkPage.qml b/desktop/modules/network/NetworkPage.qml
index e0f32e8..563251e 100644
--- a/desktop/modules/network/NetworkPage.qml
+++ b/desktop/modules/network/NetworkPage.qml
@@ -36,23 +36,7 @@ Column {
// The rates are Perf's, sampled always, so the graph opens on the last
// minute rather than empty.
- Row {
- spacing: 6
-
- Text {
- anchors.verticalCenter: parent.verticalCenter
- text: String.fromCodePoint(0xF012A)
- font { family: Theme.iconFamily; pixelSize: Theme.fontSize - 2 }
- color: Theme.subtext
- }
-
- Text {
- anchors.verticalCenter: parent.verticalCenter
- text: "Traffic · " + Perf.iface
- font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2; bold: true }
- color: Theme.subtext
- }
- }
+ SectionHeader { divider: false; glyph: String.fromCodePoint(0xF012A); label: "Traffic · " + Perf.iface }
Canvas {
id: graph
@@ -230,29 +214,105 @@ Column {
}
}
- Rectangle { width: page.width; height: 1; color: Qt.alpha(Theme.text, 0.12) }
+ // --- Speedtest ---
- // --- Wired ---
+ // The run and its result live in the module (see there).
+ SectionHeader { glyph: "\uf0e4"; label: "Speedtest" }
- Row {
- visible: page.net.wiredDevices.length > 0
- spacing: 6
+ Item {
+ width: page.width
+ implicitHeight: Math.max(speedBtn.implicitHeight, speedText.implicitHeight)
- Text {
+ Button {
+ id: speedBtn
anchors.verticalCenter: parent.verticalCenter
- text: "\uef44"
- font { family: Theme.iconFamily; pixelSize: Theme.fontSize - 2 }
- color: Theme.subtext
+ text: page.net.speedRunning ? "Testing…" : "Speedtest"
+ onClicked: if (!page.net.speedRunning) page.net.runSpeedtest()
}
Text {
- anchors.verticalCenter: parent.verticalCenter
- text: "Wired"
- font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2; bold: true }
- color: Theme.subtext
+ id: speedText
+ anchors { right: parent.right; verticalCenter: parent.verticalCenter }
+ text: {
+ const n = page.net, r = n.speedResult;
+ if (r) return "↓ " + r.down.toFixed(0) + " ↑ " + r.up.toFixed(0)
+ + " Mbit/s · " + r.ping.toFixed(0) + " ms";
+ if (n.speedPhase === "ping") return "Ping…";
+ if (n.speedPhase) return (n.speedPhase === "download" ? "↓ " : "↑ ")
+ + n.speedLive.toFixed(0) + " Mbit/s";
+ return "";
+ }
+ font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2 }
+ font.features: { "tnum": 1 }
+ color: page.net.speedPhase === "download" ? Theme.teal
+ : page.net.speedPhase === "upload" ? Theme.peach : Theme.text
+ }
+ }
+
+ // The current phase's progress, coloured like its curve below.
+ Rectangle {
+ width: page.width
+ height: 4
+ radius: 2
+ visible: page.net.speedRunning
+ color: Qt.alpha(Theme.text, 0.12)
+ Rectangle {
+ width: parent.width * page.net.speedProgress
+ height: parent.height
+ radius: 2
+ color: page.net.speedPhase === "upload" ? Theme.peach
+ : page.net.speedPhase === "download" ? Theme.teal : Theme.subtext
+ Behavior on width { NumberAnimation { duration: 150 } }
}
}
+ // Both runs on one Mbit/s scale, each stretched to the full width, so
+ // their shapes compare directly; drawn live and kept with the result.
+ Canvas {
+ id: speedGraph
+ width: page.width
+ height: 60
+ visible: page.net.speedDown.length > 0
+ onPaint: {
+ const ctx = getContext("2d");
+ ctx.reset();
+ const d = page.net.speedDown, u = page.net.speedUp;
+ const max = Math.max(1, ...d, ...u);
+ const line = (data, color) => {
+ if (data.length < 2) return;
+ ctx.strokeStyle = color;
+ ctx.lineWidth = 1.5;
+ ctx.beginPath();
+ data.forEach((v, i) => {
+ const x = width * i / (data.length - 1);
+ const y = height - 1 - (height - 2) * v / max;
+ if (i) ctx.lineTo(x, y); else ctx.moveTo(x, y);
+ });
+ ctx.stroke();
+ };
+ line(d, Theme.teal);
+ line(u, Theme.peach);
+ }
+ Connections {
+ target: page.net
+ function onSpeedDownChanged() { speedGraph.requestPaint(); }
+ function onSpeedUpChanged() { speedGraph.requestPaint(); }
+ }
+ }
+
+ Text {
+ width: page.width
+ visible: page.net.speedResult !== null
+ text: page.net.speedResult ? page.net.speedResult.server : ""
+ elide: Text.ElideRight
+ font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 3 }
+ color: Theme.subtext
+ }
+
+ // --- Wired ---
+
+ SectionHeader { visible: page.net.wiredDevices.length > 0; glyph: "\uef44"; label: "Wired" }
+
Repeater {
model: page.net.wiredDevices
@@ -281,33 +341,14 @@ Column {
}
}
- Rectangle { width: page.width; height: 1; visible: page.net.wiredDevices.length > 0; color: Qt.alpha(Theme.text, 0.12) }
-
// --- Wifi ---
- Item {
- width: page.width
- implicitHeight: Math.max(wifiLabel.implicitHeight, wifiSwitch.implicitHeight)
-
- Text {
- id: wifiLabel
- anchors { left: wifiGlyph.right; leftMargin: 6; verticalCenter: parent.verticalCenter }
- text: "Wi-Fi"
- font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 1; bold: true }
- color: Theme.text
- }
-
- Text {
- id: wifiGlyph
- anchors.verticalCenter: parent.verticalCenter
- text: "\uf1eb"
- font { family: Theme.iconFamily; pixelSize: Theme.fontSize - 2 }
- color: Theme.subtext
- }
+ SectionHeader {
+ glyph: "\uf1eb"
+ label: "Wi-Fi"
Switch {
- id: wifiSwitch
- anchors { right: parent.right; verticalCenter: parent.verticalCenter }
+ anchors { right: parent.right; bottom: parent.bottom }
enabled: Networking.wifiHardwareEnabled
checked: page.net.wifiOn
onToggled: on => Networking.wifiEnabled = on