forked from Shinonome/dots-hyprland
Add more status in the network icon (#2154)
This commit is contained in:
@@ -10,7 +10,7 @@ import Quickshell.Io
|
|||||||
import Quickshell.Hyprland
|
import Quickshell.Hyprland
|
||||||
|
|
||||||
QuickToggleButton {
|
QuickToggleButton {
|
||||||
toggled: Network.wifiEnabled
|
toggled: Network.wifiStatus !== "disabled"
|
||||||
buttonIcon: Network.materialSymbol
|
buttonIcon: Network.materialSymbol
|
||||||
onClicked: Network.toggleWifi()
|
onClicked: Network.toggleWifi()
|
||||||
altAction: () => {
|
altAction: () => {
|
||||||
|
|||||||
@@ -16,24 +16,35 @@ Singleton {
|
|||||||
|
|
||||||
property bool wifi: true
|
property bool wifi: true
|
||||||
property bool ethernet: false
|
property bool ethernet: false
|
||||||
|
|
||||||
property bool wifiEnabled: false
|
property bool wifiEnabled: false
|
||||||
property bool wifiScanning: false
|
property bool wifiScanning: false
|
||||||
property bool wifiConnecting: connectProc.running
|
property bool wifiConnecting: connectProc.running
|
||||||
property WifiAccessPoint wifiConnectTarget
|
property WifiAccessPoint wifiConnectTarget
|
||||||
readonly property list<WifiAccessPoint> wifiNetworks: []
|
readonly property list<WifiAccessPoint> wifiNetworks: []
|
||||||
readonly property WifiAccessPoint active: wifiNetworks.find(n => n.active) ?? null
|
readonly property WifiAccessPoint active: wifiNetworks.find(n => n.active) ?? null
|
||||||
|
property string wifiStatus: "disconnected"
|
||||||
|
|
||||||
property string networkName: ""
|
property string networkName: ""
|
||||||
property int networkStrength
|
property int networkStrength
|
||||||
property string materialSymbol: ethernet ? "lan" :
|
property string materialSymbol: root.ethernet
|
||||||
wifiEnabled ? (
|
? "lan"
|
||||||
Network.networkStrength > 80 ? "signal_wifi_4_bar" :
|
: root.wifiEnabled
|
||||||
Network.networkStrength > 60 ? "network_wifi_3_bar" :
|
? (
|
||||||
Network.networkStrength > 40 ? "network_wifi_2_bar" :
|
Network.networkStrength > 83 ? "signal_wifi_4_bar" :
|
||||||
Network.networkStrength > 20 ? "network_wifi_1_bar" :
|
Network.networkStrength > 67 ? "network_wifi" :
|
||||||
"signal_wifi_0_bar"
|
Network.networkStrength > 50 ? "network_wifi_3_bar" :
|
||||||
) : "signal_wifi_off"
|
Network.networkStrength > 33 ? "network_wifi_2_bar" :
|
||||||
|
Network.networkStrength > 17 ? "network_wifi_1_bar" :
|
||||||
|
"signal_wifi_0_bar"
|
||||||
|
)
|
||||||
|
: (root.wifiStatus === "connecting")
|
||||||
|
? "signal_wifi_statusbar_not_connected"
|
||||||
|
: (root.wifiStatus === "disconnected")
|
||||||
|
? "wifi_find"
|
||||||
|
: (root.wifiStatus === "disabled")
|
||||||
|
? "signal_wifi_off"
|
||||||
|
: "signal_wifi_bad"
|
||||||
|
|
||||||
// Control
|
// Control
|
||||||
function enableWifi(enabled = true): void {
|
function enableWifi(enabled = true): void {
|
||||||
@@ -153,7 +164,7 @@ Singleton {
|
|||||||
Process {
|
Process {
|
||||||
id: updateConnectionType
|
id: updateConnectionType
|
||||||
property string buffer
|
property string buffer
|
||||||
command: ["sh", "-c", "nmcli -t -f NAME,TYPE,DEVICE c show --active"]
|
command: ["sh", "-c", "nmcli -t -f TYPE,STATE d status && nmcli -t -f CONNECTIVITY g"]
|
||||||
running: true
|
running: true
|
||||||
function startCheck() {
|
function startCheck() {
|
||||||
buffer = "";
|
buffer = "";
|
||||||
@@ -166,14 +177,35 @@ Singleton {
|
|||||||
}
|
}
|
||||||
onExited: (exitCode, exitStatus) => {
|
onExited: (exitCode, exitStatus) => {
|
||||||
const lines = updateConnectionType.buffer.trim().split('\n');
|
const lines = updateConnectionType.buffer.trim().split('\n');
|
||||||
|
const connectivity = lines.pop() // none, limited, full
|
||||||
let hasEthernet = false;
|
let hasEthernet = false;
|
||||||
let hasWifi = false;
|
let hasWifi = false;
|
||||||
|
let wifiStatus = "disconnected";
|
||||||
lines.forEach(line => {
|
lines.forEach(line => {
|
||||||
if (line.includes("ethernet"))
|
if (line.includes("ethernet") && line.includes("connected"))
|
||||||
hasEthernet = true;
|
hasEthernet = true;
|
||||||
else if (line.includes("wireless"))
|
else if (line.includes("wifi:")) {
|
||||||
hasWifi = true;
|
if (line.includes("disconnected")) {
|
||||||
|
wifiStatus = "disconnected"
|
||||||
|
}
|
||||||
|
else if (line.includes("connected")) {
|
||||||
|
hasWifi = true;
|
||||||
|
wifiStatus = "connected"
|
||||||
|
|
||||||
|
if (connectivity === "limited") {
|
||||||
|
hasWifi = false;
|
||||||
|
wifiStatus = "limited"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (line.includes("connecting")) {
|
||||||
|
wifiStatus = "connecting"
|
||||||
|
}
|
||||||
|
else if (line.includes("unavailable")) {
|
||||||
|
wifiStatus = "disabled"
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
root.wifiStatus = wifiStatus;
|
||||||
root.ethernet = hasEthernet;
|
root.ethernet = hasEthernet;
|
||||||
root.wifi = hasWifi;
|
root.wifi = hasWifi;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user