87 lines
2.5 KiB
QML
87 lines
2.5 KiB
QML
import Quickshell
|
|
import Quickshell.Io
|
|
import QtQuick
|
|
import "../components"
|
|
|
|
Item {
|
|
id: root
|
|
implicitWidth: row.implicitWidth + 10
|
|
implicitHeight: 24
|
|
|
|
property string connType: "none" // "wifi", "ethernet", "none"
|
|
property string connName: ""
|
|
|
|
// accumulate results here, flush to displayed props on exit
|
|
property string _pendingType: "none"
|
|
property string _pendingName: ""
|
|
|
|
// \uf1eb = FA wifi, \uf0e8 = FA sitemap (wired proxy), \uf127 = FA chain-broken
|
|
readonly property string netIcon:
|
|
connType === "wifi" ? "\uf1eb" :
|
|
connType === "ethernet" ? "\uf0e8" : "\uf127"
|
|
|
|
function parseLine(line) {
|
|
const idx1 = line.indexOf(":")
|
|
if (idx1 < 0) return
|
|
const idx2 = line.indexOf(":", idx1 + 1)
|
|
if (idx2 < 0) return
|
|
const type = line.substring(0, idx1)
|
|
const state = line.substring(idx1 + 1, idx2)
|
|
const conn = line.substring(idx2 + 1).trim()
|
|
if (state === "connected" && (type === "wifi" || type === "ethernet")) {
|
|
if (root._pendingType === "none" || type === "wifi") {
|
|
root._pendingType = type
|
|
root._pendingName = conn
|
|
}
|
|
}
|
|
}
|
|
|
|
Timer {
|
|
interval: 5000
|
|
running: true
|
|
repeat: true
|
|
triggeredOnStart: true
|
|
onTriggered: {
|
|
root._pendingType = "none"
|
|
root._pendingName = ""
|
|
netProc.running = true
|
|
}
|
|
}
|
|
|
|
Process {
|
|
id: netProc
|
|
command: ["nmcli", "-t", "-f", "TYPE,STATE,CONNECTION", "dev"]
|
|
stdout: SplitParser {
|
|
splitMarker: "\n"
|
|
onRead: data => root.parseLine(data)
|
|
}
|
|
onExited: {
|
|
root.connType = root._pendingType
|
|
root.connName = root._pendingName
|
|
running = false
|
|
}
|
|
}
|
|
|
|
Row {
|
|
id: row
|
|
anchors.centerIn: parent
|
|
spacing: 5
|
|
|
|
Text {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
text: root.netIcon
|
|
font.family: "JetBrainsMono Nerd Font Mono"
|
|
font.pixelSize: 14
|
|
color: root.connType !== "none" ? Theme.text : Theme.textDim
|
|
}
|
|
|
|
Text {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
text: root.connName.length > 16 ? root.connName.substring(0, 15) + "…" : root.connName
|
|
font.pixelSize: 11
|
|
color: Theme.textDim
|
|
visible: root.connName !== ""
|
|
}
|
|
}
|
|
}
|