Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 24 additions & 0 deletions shell/plugins/panels/network/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@ function wifiIconFor(strength) {
return icons[index]
}

// The connected network's own strength comes from the access points
// Quickshell grouped under its SSID. When it has none (an OWE transition-mode
// network between scans files the in-use access point under its hidden
// "_owetm_" twin), fall back to the strength NetworkManager reports for the
// access point in use.
function connectedSignalStrength(networkStrength, activeApSignal) {
var strength = Math.round((networkStrength || 0) * 100)
if (strength > 0) return strength
return activeApSignal > 0 ? activeApSignal : strength
}

// Reads `nmcli -t -f IN-USE,SIGNAL device wifi list` output, where the in-use
// access point is the row marked "*".
function parseActiveApSignal(raw) {
var lines = String(raw || "").split(/\r?\n/)
for (var i = 0; i < lines.length; i++) {
var match = /^\*:(\d+)$/.exec(lines[i].trim())
if (match) return parseInt(match[1], 10)
}
return -1
}

// A known plain-HTTP endpoint lets the network redirect the browser to its
// login page. Never execute or automatically open an untrusted Location header.
var captivePortalUrl = "http://ping.archlinux.org/nm-check.txt"
Expand Down Expand Up @@ -368,6 +390,8 @@ if (typeof module !== "undefined") {
parseNetworkStatus: parseNetworkStatus,
wifiIconFor: wifiIconFor,
connectionIcon: connectionIcon,
connectedSignalStrength: connectedSignalStrength,
parseActiveApSignal: parseActiveApSignal,
connectivityState: connectivityState,
captivePortalUrl: captivePortalUrl,
formatHeaderSpeed: formatHeaderSpeed,
Expand Down
41 changes: 37 additions & 4 deletions shell/plugins/panels/network/Panel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,24 @@ Panel {
readonly property string kind: {
if (wiredDevice && wiredDevice.connected) return "ethernet"
if (connectedWifiNetwork) return "wifi"
// NetworkManager can leave the active profile out of the device's
// AvailableConnections, and Quickshell only builds known networks from
// that list. An OWE transition-mode network does this between scans: the
// in-use access point carries the hidden "_owetm_" SSID, so the profile
// for the open SSID looks out of range even while it is connected. Trust
// the device's own state then instead of flickering to disconnected.
if (wifiDevice && wifiDevice.connected) return "wifi"
return "disconnected"
}
readonly property int signalStrength: connectedWifiNetwork
? Math.round((connectedWifiNetwork.signalStrength || 0) * 100)
readonly property int signalStrength: kind === "wifi"
? Model.connectedSignalStrength(connectedWifiNetwork ? connectedWifiNetwork.signalStrength : 0, activeApSignal)
: -1
// Filled by activeApSignalPoll from nmcli while the connected network has no
// strength of its own to report.
property int activeApSignal: -1
readonly property bool needsActiveApSignal: kind === "wifi"
&& !(connectedWifiNetwork && connectedWifiNetwork.signalStrength > 0)
onKindChanged: if (kind !== "wifi") activeApSignal = -1
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved

function copyToClipboard(value) {
if (!value || !root.bar) return
Expand All @@ -464,8 +477,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 : "")
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved

onConnectionKeyChanged: Qt.callLater(checkConnectivity)
Expand Down Expand Up @@ -871,6 +884,26 @@ Panel {
}
}

// Reads the in-use access point's strength without triggering a scan, for
// the connected network that has none of its own (see signalStrength).
Process {
id: activeApSignalProc
command: ["nmcli", "-t", "-f", "IN-USE,SIGNAL", "device", "wifi", "list", "ifname", root.wifiDevice ? root.wifiDevice.name : "", "--rescan", "no"]
stdout: StdioCollector {
waitForEnd: true
onStreamFinished: root.activeApSignal = Model.parseActiveApSignal(text)
}
}

Timer {
id: activeApSignalPoll
interval: 5000
repeat: true
triggeredOnStart: true
running: root.needsActiveApSignal
onTriggered: if (!activeApSignalProc.running) activeApSignalProc.running = true
}

Timer {
id: scanRestart
interval: 100
Expand Down
21 changes: 21 additions & 0 deletions test/shell.d/network-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@ assertDeepEqual(
'network parses bar status'
)
assertEqual(network.connectionIcon('wifi', 80), network.wifiIconFor(80), 'network maps wifi icon from signal')

// OWE transition mode: between scans NetworkManager files the in-use access
// point under the hidden "_owetm_" SSID and drops the active profile from the
// device's AvailableConnections, so Quickshell lists no connected network. The
// bar trusts the device's own state and reads the in-use AP's strength instead
// of flickering to disconnected.
const kindBinding = panelSource.match(/readonly property string kind: \{[\s\S]*?\n {2}\}/)
assert(kindBinding, 'network has a kind binding')
assert(/if \(wifiDevice && wifiDevice\.connected\) return "wifi"/.test(kindBinding[0]), 'network keeps showing Wi-Fi while the device is connected but no network is listed as connected')
assert(
kindBinding[0].indexOf('connectedWifiNetwork) return "wifi"') < kindBinding[0].indexOf('wifiDevice.connected) return "wifi"'),
'network prefers the listed connected network before falling back to device state'
)
assertEqual(network.connectedSignalStrength(0.8, 40), 80, 'network prefers the connected network strength')
assertEqual(network.connectedSignalStrength(0, 67), 67, 'network falls back to the in-use access point strength')
assertEqual(network.connectedSignalStrength(0, -1), 0, 'network reports no strength when the in-use access point is unknown')
assertEqual(network.parseActiveApSignal(' :82\n*:67\n :50\n'), 67, 'network parses the in-use access point strength from nmcli')
assertEqual(network.parseActiveApSignal(' :82\n'), -1, 'network reports no in-use access point when none is marked')
assertEqual(network.parseActiveApSignal(''), -1, 'network tolerates empty nmcli output')
assert(/running: root\.needsActiveApSignal/.test(panelSource), 'network only polls the in-use access point while the connected network lacks a strength')
assert(/"--rescan", "no"/.test(panelSource), 'network reads the in-use access point without triggering a scan')
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
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