Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions shell/plugins/panels/network/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ function connectionIcon(kind, signalStrength, connectivity) {
return "󰤮"
}

function connectionKind(wiredConnected, wifiNetworkConnected, wifiDeviceConnected) {
if (wiredConnected) return "ethernet"
if (wifiNetworkConnected || wifiDeviceConnected) return "wifi"
return "disconnected"
}

function connectionSignalStrength(networkStrength, wifiConnected) {
if (networkStrength !== null && networkStrength !== undefined) {
return Math.round((networkStrength || 0) * 100)
}

return wifiConnected ? 0 : -1
Comment thread
patrickrodrigues-aa marked this conversation as resolved.
Resolved
}

function formatHeaderSpeed(mbps) {
var v = parseInt(mbps, 10)
if (!v || v < 0) return ""
Expand Down Expand Up @@ -368,6 +382,8 @@ if (typeof module !== "undefined") {
parseNetworkStatus: parseNetworkStatus,
wifiIconFor: wifiIconFor,
connectionIcon: connectionIcon,
connectionKind: connectionKind,
connectionSignalStrength: connectionSignalStrength,
connectivityState: connectivityState,
captivePortalUrl: captivePortalUrl,
formatHeaderSpeed: formatHeaderSpeed,
Expand Down
29 changes: 18 additions & 11 deletions shell/plugins/panels/network/Panel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -436,16 +436,23 @@ Panel {

// Bar pill state, derived from the native NetworkManager service so the
// icon reflects connection changes without polling. Wired is preferred
// when both are up, matching the default-route device.
// when both are up, matching the default-route device. Quickshell 0.3.1
// ignores a profile with no 802-11-wireless.mode, so a connected station can
// have no connected network: keep the bar online from device state then.
// Only in station mode: a card running a hotspot is connected with no uplink.
readonly property var wiredDevice: findDevice(DeviceType.Wired)
readonly property string kind: {
if (wiredDevice && wiredDevice.connected) return "ethernet"
if (connectedWifiNetwork) return "wifi"
return "disconnected"
}
readonly property int signalStrength: connectedWifiNetwork
? Math.round((connectedWifiNetwork.signalStrength || 0) * 100)
: -1
readonly property bool wifiStationConnected: !!(wifiDevice && wifiDevice.connected
&& wifiDevice.mode === WifiDeviceMode.Station)
readonly property bool wifiConnected: !!connectedWifiNetwork || wifiStationConnected
readonly property string kind: Model.connectionKind(
!!(wiredDevice && wiredDevice.connected),
!!connectedWifiNetwork,
wifiStationConnected
)
readonly property int signalStrength: Model.connectionSignalStrength(
connectedWifiNetwork ? connectedWifiNetwork.signalStrength : null,
wifiConnected
)

function copyToClipboard(value) {
if (!value || !root.bar) return
Expand All @@ -464,8 +471,8 @@ Panel {
readonly property bool hasCaptivePortal: connectivity === "portal"
readonly property bool restricted: hasCaptivePortal || connectivity === "limited"
readonly property string icon: Model.connectionIcon(kind, signalStrength, connectivity)
readonly property string connectionKey: kind === "wifi" && wifiDevice && connectedWifiNetwork
? kind + ":" + wifiDevice.name + ":" + connectedWifiNetwork.name
readonly property string connectionKey: kind === "wifi" && wifiDevice
? kind + ":" + wifiDevice.name + ":" + (connectedWifiNetwork ? connectedWifiNetwork.name : "")
: (kind === "ethernet" && wiredDevice ? kind + ":" + wiredDevice.name : "")

onConnectionKeyChanged: Qt.callLater(checkConnectivity)
Expand Down
19 changes: 19 additions & 0 deletions test/shell.d/network-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ assertDeepEqual(
'network parses bar status'
)
assertEqual(network.connectionIcon('wifi', 80), network.wifiIconFor(80), 'network maps wifi icon from signal')
assertEqual(network.connectionKind(false, false, false), 'disconnected', 'network reports disconnected when no device is online')
assertEqual(network.connectionKind(true, true, true), 'ethernet', 'network prefers ethernet when multiple devices are online')
assertEqual(network.connectionKind(false, true, false), 'wifi', 'network reports wifi from a connected access point')
assertEqual(network.connectionKind(false, false, true), 'wifi', 'network reports wifi from a connected device when access points are missing')
assert(
/wifiStationConnected: !!\(wifiDevice && wifiDevice\.connected\s*&& wifiDevice\.mode === WifiDeviceMode\.Station\)/.test(panelSource),
'network counts a connected Wi-Fi device as online only in station mode, not while it runs a hotspot'
)
assert(
/kind: Model\.connectionKind\([\s\S]*?!!connectedWifiNetwork,\s*wifiStationConnected\s*\)/.test(panelSource),
'network keeps the bar on Wi-Fi when the device is connected but no access point object is'
)
assert(
/connectionKey: kind === "wifi" && wifiDevice\n\s*\? kind \+ ":" \+ wifiDevice\.name \+ ":" \+ \(connectedWifiNetwork \? connectedWifiNetwork\.name : ""\)\n/.test(panelSource),
'network rechecks connectivity when Wi-Fi comes up without an access point object'
Comment thread
patrickrodrigues-aa marked this conversation as resolved.
Resolved
)
assertEqual(network.connectionSignalStrength(0.78, true), 78, 'network maps access-point signal strength to percent')
assertEqual(network.connectionSignalStrength(null, true), 0, 'network keeps connected wifi online when signal strength is unknown')
assertEqual(network.connectionSignalStrength(null, false), -1, 'network has no signal strength while disconnected')
assertEqual(network.formatHeaderSpeed('1000'), '1gbit', 'network formats gigabit speed')
assertEqual(network.formatHeaderSpeed('2500'), '2.5gbit', 'network formats fractional gigabit speed')
assertEqual(network.formatHeaderFreq('2462'), '2.4ghz', 'network formats 2.4GHz wifi band')
Expand Down