me like nix
1pragma Singleton
2
3import QtQuick
4import Quickshell
5import Quickshell.Io
6
7QtObject {
8 readonly property bool connected: _connected
9 readonly property bool isEthernet: _isEthernet
10 readonly property string name: _name
11 readonly property int strength: _strength
12
13 property bool _connected: false
14 property bool _isEthernet: false
15 property string _name: ""
16 property int _strength: 0
17
18 property var _proc: Process {
19 command: ["sh", "-c", "eth=$(nmcli -t -f TYPE,STATE,CONNECTION dev | grep '^ethernet:connected:' | head -1); if [ -n \"$eth\" ]; then echo \"ethernet:$(echo $eth | cut -d: -f3)\"; else nmcli -t -f ACTIVE,SSID,SIGNAL dev wifi | grep '^yes' | head -1; fi"]
20 stdout: SplitParser {
21 onRead: data => {
22 if (!data || data.trim() === "") {
23 _connected = false
24 _isEthernet = false
25 _name = "Disconnected"
26 _strength = 0
27 return
28 }
29 var trimmed = data.trim()
30 if (trimmed.startsWith("ethernet:")) {
31 _connected = true
32 _isEthernet = true
33 _name = trimmed.split(":")[1] || "Ethernet"
34 _strength = 100
35 } else {
36 var parts = trimmed.split(":")
37 _connected = true
38 _isEthernet = false
39 _name = parts[1] || ""
40 _strength = parseInt(parts[2]) || 0
41 }
42 }
43 }
44 Component.onCompleted: running = true
45 }
46
47 property var _timer: Timer {
48 interval: 2000
49 running: true
50 repeat: true
51 onTriggered: _proc.running = true
52 }
53}