feat(bar): add home latency indicator widget

This commit is contained in:
tux
2026-08-23 18:17:53 +05:30
parent 3b01362a5a
commit ab15dcf0ac
4 changed files with 64 additions and 1 deletions

50
services/Home.qml Normal file
View File

@@ -0,0 +1,50 @@
pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
Singleton {
id: root
property string host: "100.64.0.3"
property int interval: 5000
// Round-trip time in ms; -1 means unknown/unreachable.
property int latency: -1
property bool replied: false
readonly property url icon: `${Quickshell.shellPath("assets")}/icons/home.svg`
function ping(): void {
proc.command = ["ping", "-c", "1", "-W", "2", root.host];
root.replied = false;
proc.running = true;
}
Timer {
interval: root.interval
running: true
repeat: true
triggeredOnStart: true
onTriggered: root.ping()
}
Process {
id: proc
stdout: SplitParser {
onRead: line => {
const match = line.match(/time[=<]([\d.]+)\s*ms/);
if (match) {
root.latency = Math.round(parseFloat(match[1]));
root.replied = true;
}
}
}
onExited: {
if (!root.replied)
root.latency = -1;
}
}
}