summaryrefslogtreecommitdiff
path: root/services/Network.qml
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-07-12 18:15:32 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-07-12 18:15:32 +0800
commit299bf0bae8be6ab505f97d6aba4f82e4e6f96f62 (patch)
treee1a72a68b5c2fae7fab097a80462233878a3231c /services/Network.qml
parentce5f49a9324bceccab821c1d2ebf3f72bdfc09ea (diff)
lot of minor improvement added utils and working networkusage
Diffstat (limited to 'services/Network.qml')
-rw-r--r--services/Network.qml86
1 files changed, 86 insertions, 0 deletions
diff --git a/services/Network.qml b/services/Network.qml
new file mode 100644
index 0000000..52f15fa
--- /dev/null
+++ b/services/Network.qml
@@ -0,0 +1,86 @@
+pragma Singleton
+// pragma ComponentBehavior: Bound
+
+import Quickshell
+import Quickshell.Io
+import QtQuick
+
+import qs.config
+
+Singleton {
+ id: root
+
+ property bool wifi: true
+ property bool ethernet: false
+ property string networkName: ""
+ property int networkStrength
+ // property string materialSymbol: ethernet ? "lan" : (Network.networkName.length > 0 && Network.networkName != "lo") ? (Network.networkStrength > 80 ? "signal_wifi_4_bar" : Network.networkStrength > 60 ? "network_wifi_3_bar" : Network.networkStrength > 40 ? "network_wifi_2_bar" : Network.networkStrength > 20 ? "network_wifi_1_bar" : "signal_wifi_0_bar") : "signal_wifi_off"
+ property string state: ethernet ? Icons.resource.network.wifi : (networkName.length >= 0 && networkName !== "lo") ? (networkStrength >= 90 ? Icons.resource.network.wifi.max : networkStrength >= 80 ? Icons.resource.network.wifi.high : networkStrength >= 60 ? Icons.resource.network.wifi.mid : networkStrength >= 40 ? Icons.resource.network.wifi.low : networkStrength >= 20 ? Icons.resource.network.wifi.min : Icons.resource.network.disconnected) : Icons.resource.network.disconnected
+
+ function update() {
+ updateConnectionType.startCheck();
+ updateNetworkName.running = true;
+ updateNetworkStrength.running = true;
+ }
+
+ Timer {
+ interval: General.resourceUpdateInterval
+ running: true
+ repeat: true
+ onTriggered: {
+ root.update();
+ interval = General.resourceUpdateInterval * 1000;
+ }
+ }
+
+ Process {
+ id: updateConnectionType
+ property string buffer
+ command: ["nmcli", "-t", "-f", "NAME,TYPE,DEVICE", "c", "show", "--active"]
+ running: true
+ function startCheck() {
+ buffer = "";
+ updateConnectionType.running = true;
+ }
+ stdout: SplitParser {
+ onRead: data => {
+ updateConnectionType.buffer += data + "\n";
+ }
+ }
+ onExited: (exitCode, exitStatus) => {
+ const lines = updateConnectionType.buffer.trim().split('\n');
+ let hasEthernet = false;
+ let hasWifi = false;
+ lines.forEach(line => {
+ if (line.includes("ethernet"))
+ hasEthernet = true;
+ else if (line.includes("wireless"))
+ hasWifi = true;
+ });
+ root.ethernet = hasEthernet;
+ root.wifi = hasWifi;
+ }
+ }
+
+ Process {
+ id: updateNetworkName
+ command: ["sh", "-c", "nmcli -t -f NAME c show --active | head -1"]
+ running: true
+ stdout: SplitParser {
+ onRead: data => {
+ root.networkName = data;
+ }
+ }
+ }
+
+ Process {
+ id: updateNetworkStrength
+ running: true
+ command: ["sh", "-c", "nmcli -f IN-USE,SIGNAL,SSID device wifi | awk '/^\*/{if (NR!=1) {print $2}}'"]
+ stdout: SplitParser {
+ onRead: data => {
+ root.networkStrength = parseInt(data);
+ }
+ }
+ }
+}