Skip to content

Commit ec03b44

Browse files
committed
Add network widget
1 parent e213256 commit ec03b44

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import QtQuick
2+
import QtQuick.Layouts
3+
import Quickshell
4+
import Quickshell.Networking
5+
6+
RowLayout {
7+
id: root
8+
spacing: 6
9+
10+
property int fontSize: 14
11+
property color colFg: "#ffffff"
12+
13+
readonly property var devicesList: Networking.devices.values
14+
readonly property string uplinkIcon: hasActiveVpn ? "" : ""
15+
16+
readonly property bool hasActiveVpn: {
17+
var devices = devicesList;
18+
for (var i = 0; i < devices.length; i++) {
19+
var dev = devices[i];
20+
21+
if (dev && dev.connected && dev.name) {
22+
var name = dev.name.toLowerCase();
23+
if (name.startsWith("tun") || name.startsWith("tap") || name.startsWith("wg") || name.startsWith("ppp")) {
24+
return true;
25+
}
26+
}
27+
}
28+
29+
return false;
30+
}
31+
32+
readonly property var primaryDevice: {
33+
var devices = devicesList;
34+
if (devices.length === 0)
35+
return null;
36+
37+
var connectedDev = null;
38+
var firstDev = null;
39+
40+
for (var i = 0; i < devices.length; i++) {
41+
var dev = devices[i];
42+
if (!dev)
43+
continue;
44+
45+
if (!firstDev)
46+
firstDev = dev;
47+
48+
if (dev.state === DeviceConnectionState.Connected) {
49+
connectedDev = dev;
50+
return dev;
51+
}
52+
}
53+
54+
return connectedDev || firstDev;
55+
}
56+
57+
readonly property bool isPrimaryWifi: {
58+
if (!primaryDevice)
59+
return false;
60+
61+
return primaryDevice.type === DeviceType.Wifi;
62+
}
63+
64+
Text {
65+
text: root.uplinkIcon
66+
color: root.colFg
67+
font.family: "Symbols Nerd Font"
68+
font.pixelSize: root.fontSize
69+
}
70+
71+
Text {
72+
text: isPrimaryWifi ? "" : "󰈀"
73+
color: root.colFg
74+
font.family: "Symbols Nerd Font"
75+
font.pixelSize: root.fontSize
76+
}
77+
}

0 commit comments

Comments
 (0)