forked from Shinonome/dots-hyprland
make network indicator work with ethernet
This commit is contained in:
@@ -10,8 +10,6 @@ import Qt5Compat.GraphicalEffects
|
|||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Wayland
|
import Quickshell.Wayland
|
||||||
import Quickshell.Hyprland
|
import Quickshell.Hyprland
|
||||||
import Quickshell.Io
|
|
||||||
import Quickshell.Services.Mpris
|
|
||||||
import Quickshell.Services.UPower
|
import Quickshell.Services.UPower
|
||||||
|
|
||||||
Scope {
|
Scope {
|
||||||
@@ -393,13 +391,7 @@ Scope {
|
|||||||
}
|
}
|
||||||
MaterialSymbol {
|
MaterialSymbol {
|
||||||
Layout.rightMargin: indicatorsRowLayout.realSpacing
|
Layout.rightMargin: indicatorsRowLayout.realSpacing
|
||||||
text: (Network.networkName.length > 0 && Network.networkName != "lo") ? (
|
text: Network.materialSymbol
|
||||||
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"
|
|
||||||
iconSize: Appearance.font.pixelSize.larger
|
iconSize: Appearance.font.pixelSize.larger
|
||||||
color: rightSidebarButton.colText
|
color: rightSidebarButton.colText
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,13 +10,7 @@ import Quickshell.Hyprland
|
|||||||
|
|
||||||
QuickToggleButton {
|
QuickToggleButton {
|
||||||
toggled: Network.networkName.length > 0 && Network.networkName != "lo"
|
toggled: Network.networkName.length > 0 && Network.networkName != "lo"
|
||||||
buttonIcon: toggled ? (
|
buttonIcon: Network.materialSymbol
|
||||||
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"
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
toggleNetwork.running = true
|
toggleNetwork.running = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
pragma Singleton
|
pragma Singleton
|
||||||
pragma ComponentBehavior: Bound
|
pragma ComponentBehavior: Bound
|
||||||
|
|
||||||
import Quickshell;
|
import Quickshell
|
||||||
import Quickshell.Io;
|
import Quickshell.Io
|
||||||
import Quickshell.Services.Pipewire;
|
import QtQuick
|
||||||
import QtQuick;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple polled network state service.
|
* Simple polled network state service.
|
||||||
@@ -12,12 +11,23 @@ import QtQuick;
|
|||||||
Singleton {
|
Singleton {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
|
property bool wifi: true
|
||||||
|
property bool ethernet: false
|
||||||
property int updateInterval: 1000
|
property int updateInterval: 1000
|
||||||
property string networkName: "";
|
property string networkName: ""
|
||||||
property int networkStrength;
|
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() {
|
function update() {
|
||||||
updateNetworkName.running = true
|
updateConnectionType.startCheck();
|
||||||
updateNetworkStrength.running = true
|
updateNetworkName.running = true;
|
||||||
|
updateNetworkStrength.running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
@@ -25,18 +35,47 @@ Singleton {
|
|||||||
running: true
|
running: true
|
||||||
repeat: true
|
repeat: true
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
update()
|
root.update();
|
||||||
interval = root.updateInterval;
|
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 {
|
Process {
|
||||||
id: updateNetworkName
|
id: updateNetworkName
|
||||||
command: ["sh", "-c", "nmcli -t -f NAME c show --active | head -1"]
|
command: ["sh", "-c", "nmcli -t -f NAME c show --active | head -1"]
|
||||||
running: true;
|
running: true
|
||||||
stdout: SplitParser {
|
stdout: SplitParser {
|
||||||
onRead: data => {
|
onRead: data => {
|
||||||
root.networkName = data
|
root.networkName = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,7 +83,7 @@ Singleton {
|
|||||||
Process {
|
Process {
|
||||||
id: updateNetworkStrength
|
id: updateNetworkStrength
|
||||||
running: true
|
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 {
|
stdout: SplitParser {
|
||||||
onRead: data => {
|
onRead: data => {
|
||||||
root.networkStrength = parseInt(data);
|
root.networkStrength = parseInt(data);
|
||||||
@@ -52,4 +91,3 @@ Singleton {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user