39 lines
1.5 KiB
QML
39 lines
1.5 KiB
QML
pragma Singleton
|
|
import Quickshell
|
|
import Quickshell.Networking
|
|
|
|
Singleton {
|
|
id: root
|
|
property bool wifiEnabled: Networking.wifiEnabled
|
|
readonly property list<NetworkDevice> devices: Networking.devices.values
|
|
property WifiDevice wifiDev: devices.find(dev => dev.type === DeviceType.Wifi) ?? null
|
|
property WiredDevice wiredDev: devices.find(dev => dev.type === DeviceType.Wired) ?? null
|
|
property list<WifiNetwork> wifiNetworks: wifiDev?.networks.values ?? []
|
|
property WifiNetwork connectedNet: wifiNetworks.find(net => net.connected) ?? null
|
|
function getWiredIcon() {
|
|
if (wiredDev?.hasLink ?? false) {
|
|
if (wiredDev.connected ?? false) {
|
|
return "network";
|
|
} else
|
|
return "network-slash";
|
|
} else
|
|
return "network-x";
|
|
}
|
|
function getWifiIcon() {
|
|
Networking.checkConnectivity();
|
|
let state = wifiDev?.state ?? ConnectionState.Unknown;
|
|
if (state === ConnectionState.Disconnected || state === ConnectionState.Unknown)
|
|
return "wifi-slash";
|
|
if (wifiDev?.connected ?? false) {
|
|
let strength = connectedNet?.signalStrength ?? 0.0;
|
|
if (strength <= 0.25)
|
|
return "wifi-none";
|
|
if (strength <= 0.5)
|
|
return "wifi-low";
|
|
if (strength <= 0.75)
|
|
return "wifi-medium";
|
|
if (strength > 0.75)
|
|
return "wifi-high";
|
|
}
|
|
}
|
|
}
|