60 lines
1.9 KiB
QML
60 lines
1.9 KiB
QML
import QtQuick
|
|
import Quickshell.Io
|
|
import "." as M
|
|
|
|
Row {
|
|
id: root
|
|
spacing: 4
|
|
|
|
property string ifname: ""
|
|
property string essid: ""
|
|
property string state: "disconnected"
|
|
|
|
Process {
|
|
id: proc
|
|
running: true
|
|
command: ["sh", "-c", "line=$(nmcli -t -f NAME,TYPE,DEVICE connection show --active 2>/dev/null | head -1); if [ -n \"$line\" ]; then echo \"$line\"; else dev=$(nmcli -t -f DEVICE,STATE device 2>/dev/null | grep ':connected' | grep -v ':unmanaged\\|:unavailable\\|:disconnected\\|:connecting' | head -1 | cut -d: -f1); if [ -n \"$dev\" ]; then echo \"linked:linked:$dev\"; fi; fi"]
|
|
stdout: StdioCollector {
|
|
onStreamFinished: {
|
|
const line = text.trim();
|
|
if (!line) {
|
|
root.state = "disconnected";
|
|
root.essid = "";
|
|
root.ifname = "";
|
|
return;
|
|
}
|
|
const parts = line.split(":");
|
|
root.essid = parts[0] || "";
|
|
root.ifname = parts[2] || "";
|
|
if ((parts[1] || "").includes("wireless"))
|
|
root.state = "wifi";
|
|
else if (parts[0] === "linked")
|
|
root.state = "linked";
|
|
else
|
|
root.state = "eth";
|
|
}
|
|
}
|
|
}
|
|
Timer {
|
|
interval: 5000
|
|
running: true
|
|
repeat: true
|
|
onTriggered: proc.running = true
|
|
}
|
|
|
|
Text {
|
|
text: {
|
|
if (root.state === "wifi")
|
|
return " " + root.essid;
|
|
if (root.state === "eth")
|
|
return "";
|
|
if (root.state === "linked")
|
|
return "";
|
|
return "";
|
|
}
|
|
color: M.Theme.base05
|
|
font.pixelSize: M.Theme.fontSize + 1
|
|
font.family: M.Theme.fontFamily
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
}
|
|
}
|