From 0d7769c88442bef4bca85c0afdf9f0cfb341d9c6 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sun, 1 Jun 2025 11:21:28 +0200 Subject: [PATCH] make network indicator work with ethernet --- .config/quickshell/modules/bar/Bar.qml | 10 +-- .../quickToggles/NetworkToggle.qml | 8 +-- .config/quickshell/services/Network.qml | 64 +++++++++++++++---- 3 files changed, 53 insertions(+), 29 deletions(-) diff --git a/.config/quickshell/modules/bar/Bar.qml b/.config/quickshell/modules/bar/Bar.qml index 5e4d7eb5..891c9a2c 100644 --- a/.config/quickshell/modules/bar/Bar.qml +++ b/.config/quickshell/modules/bar/Bar.qml @@ -10,8 +10,6 @@ import Qt5Compat.GraphicalEffects import Quickshell import Quickshell.Wayland import Quickshell.Hyprland -import Quickshell.Io -import Quickshell.Services.Mpris import Quickshell.Services.UPower Scope { @@ -393,13 +391,7 @@ Scope { } MaterialSymbol { Layout.rightMargin: indicatorsRowLayout.realSpacing - text: (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" + text: Network.materialSymbol iconSize: Appearance.font.pixelSize.larger color: rightSidebarButton.colText } diff --git a/.config/quickshell/modules/sidebarRight/quickToggles/NetworkToggle.qml b/.config/quickshell/modules/sidebarRight/quickToggles/NetworkToggle.qml index fc0bda11..8f058fd5 100644 --- a/.config/quickshell/modules/sidebarRight/quickToggles/NetworkToggle.qml +++ b/.config/quickshell/modules/sidebarRight/quickToggles/NetworkToggle.qml @@ -10,13 +10,7 @@ import Quickshell.Hyprland QuickToggleButton { toggled: Network.networkName.length > 0 && Network.networkName != "lo" - buttonIcon: toggled ? ( - 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" + buttonIcon: Network.materialSymbol onClicked: { toggleNetwork.running = true } diff --git a/.config/quickshell/services/Network.qml b/.config/quickshell/services/Network.qml index e2f98005..50bfb671 100644 --- a/.config/quickshell/services/Network.qml +++ b/.config/quickshell/services/Network.qml @@ -1,10 +1,9 @@ pragma Singleton pragma ComponentBehavior: Bound -import Quickshell; -import Quickshell.Io; -import Quickshell.Services.Pipewire; -import QtQuick; +import Quickshell +import Quickshell.Io +import QtQuick /** * Simple polled network state service. @@ -12,12 +11,23 @@ import QtQuick; Singleton { id: root + property bool wifi: true + property bool ethernet: false property int updateInterval: 1000 - property string networkName: ""; - property int networkStrength; + 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" function update() { - updateNetworkName.running = true - updateNetworkStrength.running = true + updateConnectionType.startCheck(); + updateNetworkName.running = true; + updateNetworkStrength.running = true; } Timer { @@ -25,18 +35,47 @@ Singleton { running: true repeat: true onTriggered: { - update() + root.update(); interval = root.updateInterval; } } + Process { + id: updateConnectionType + property string buffer + command: ["sh", "-c", "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; + running: true stdout: SplitParser { onRead: data => { - root.networkName = data + root.networkName = data; } } } @@ -44,7 +83,7 @@ Singleton { Process { id: updateNetworkStrength running: true - command: ["sh", "-c", "nmcli -f IN-USE,SIGNAL,SSID device wifi | awk '/^\*/{if (NR!=1) {print $2}}'"]; + 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); @@ -52,4 +91,3 @@ Singleton { } } } -