Show forget action for saved Wi-Fi networks
This commit is contained in:
@@ -148,7 +148,7 @@ Item {
|
|||||||
var net = wifiNetworks[selectedIndex]
|
var net = wifiNetworks[selectedIndex]
|
||||||
if (!net) return
|
if (!net) return
|
||||||
if (net.connected) { disconnect(net.ssid); return }
|
if (net.connected) { disconnect(net.ssid); return }
|
||||||
if (isProtected(net.security)) {
|
if (isProtected(net.security) && !net.known) {
|
||||||
var quotedSsid = bar.shellQuote(net.ssid)
|
var quotedSsid = bar.shellQuote(net.ssid)
|
||||||
knownCheck.targetSsid = net.ssid
|
knownCheck.targetSsid = net.ssid
|
||||||
knownCheck.command = ["bash", "-c", `
|
knownCheck.command = ["bash", "-c", `
|
||||||
@@ -167,12 +167,13 @@ iwctl known-networks list 2>/dev/null \\
|
|||||||
connectKnown(net.ssid)
|
connectKnown(net.ssid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 'x' on the highlighted row. Only meaningful on the currently-connected
|
// 'x' on the highlighted row. Meaningful for saved/known networks
|
||||||
// network — forget is a no-op (and the X icon is hidden) otherwise.
|
// (and the currently-connected row, if one is ever present); forget is
|
||||||
|
// hidden and a no-op otherwise.
|
||||||
function forgetSelected() {
|
function forgetSelected() {
|
||||||
if (busy || selectedIndex < 0 || selectedIndex >= wifiNetworks.length) return
|
if (busy || selectedIndex < 0 || selectedIndex >= wifiNetworks.length) return
|
||||||
var net = wifiNetworks[selectedIndex]
|
var net = wifiNetworks[selectedIndex]
|
||||||
if (net && net.connected) forget(net.ssid)
|
if (net && (net.connected || net.known)) forget(net.ssid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bar pill state. Polled locally so this panel is self-contained;
|
// Bar pill state. Polled locally so this panel is self-contained;
|
||||||
@@ -266,6 +267,19 @@ station=$(iwctl station list 2>/dev/null | sed -e 's/\\x1b\\[[0-9;]*m//g' | awk
|
|||||||
[[ -z $station ]] && exit 0
|
[[ -z $station ]] && exit 0
|
||||||
echo STATION_AVAILABLE
|
echo STATION_AVAILABLE
|
||||||
${scanWifi ? 'iwctl station "$station" scan >/dev/null 2>&1 || true' : ''}
|
${scanWifi ? 'iwctl station "$station" scan >/dev/null 2>&1 || true' : ''}
|
||||||
|
iwctl known-networks list 2>/dev/null \\
|
||||||
|
| sed -e 's/\\x1b\\[[0-9;]*m//g' \\
|
||||||
|
| awk '
|
||||||
|
NR <= 3 { next }
|
||||||
|
/^[[:space:]]*$/ { next }
|
||||||
|
{
|
||||||
|
line = $0
|
||||||
|
sub(/^[[:space:]]+/, "", line)
|
||||||
|
sub(/[[:space:]]+$/, "", line)
|
||||||
|
if (line ~ /^-+$/) next
|
||||||
|
n = split(line, parts, /[[:space:]]{2,}/)
|
||||||
|
if (n >= 1 && parts[1] != "") printf "KNOWN\\t%s\\n", parts[1]
|
||||||
|
}'
|
||||||
iwctl station "$station" get-networks rssi-dbms 2>/dev/null \\
|
iwctl station "$station" get-networks rssi-dbms 2>/dev/null \\
|
||||||
| sed -e 's/\\x1b\\[[0-9;]*m//g' \\
|
| sed -e 's/\\x1b\\[[0-9;]*m//g' \\
|
||||||
| awk '
|
| awk '
|
||||||
@@ -282,7 +296,7 @@ iwctl station "$station" get-networks rssi-dbms 2>/dev/null \\
|
|||||||
security = parts[n-1]
|
security = parts[n-1]
|
||||||
dbm = parts[n] / 100
|
dbm = parts[n] / 100
|
||||||
signal = (dbm >= -50) ? 100 : (dbm <= -100) ? 0 : int(2 * (dbm + 100))
|
signal = (dbm >= -50) ? 100 : (dbm <= -100) ? 0 : int(2 * (dbm + 100))
|
||||||
printf "%d\\t%s\\t%d\\t%s\\n", connected, ssid, signal, security
|
printf "NETWORK\\t%d\\t%s\\t%d\\t%s\\n", connected, ssid, signal, security
|
||||||
}'
|
}'
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
@@ -316,22 +330,38 @@ iwctl station "$station" get-networks rssi-dbms 2>/dev/null \\
|
|||||||
function updateWifi(raw) {
|
function updateWifi(raw) {
|
||||||
var lines = String(raw || "").split("\n")
|
var lines = String(raw || "").split("\n")
|
||||||
var hasStation = false
|
var hasStation = false
|
||||||
|
var knownNetworks = {}
|
||||||
var nets = []
|
var nets = []
|
||||||
|
|
||||||
for (var i = 0; i < lines.length; i++) {
|
for (var i = 0; i < lines.length; i++) {
|
||||||
var line = lines[i].trim()
|
var knownLine = lines[i].trim()
|
||||||
if (!line) continue
|
if (!knownLine) continue
|
||||||
if (line === "STATION_AVAILABLE") { hasStation = true; continue }
|
if (knownLine === "STATION_AVAILABLE") { hasStation = true; continue }
|
||||||
// Format: connected<TAB>ssid<TAB>signal<TAB>security
|
var knownParts = knownLine.split("\t")
|
||||||
|
if (knownParts.length >= 2 && knownParts[0] === "KNOWN") knownNetworks[knownParts[1]] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var j = 0; j < lines.length; j++) {
|
||||||
|
var line = lines[j].trim()
|
||||||
|
if (!line || line === "STATION_AVAILABLE") continue
|
||||||
|
// Format: NETWORK<TAB>connected<TAB>ssid<TAB>signal<TAB>security
|
||||||
|
// Older rows without the NETWORK prefix are accepted for compatibility.
|
||||||
var parts = line.split("\t")
|
var parts = line.split("\t")
|
||||||
if (parts.length < 3) continue
|
if (parts[0] === "KNOWN") continue
|
||||||
var isConnected = parts[0] === "1"
|
var offset = parts[0] === "NETWORK" ? 1 : 0
|
||||||
if (isConnected && parts[1] !== root.actionSsid) continue // Skip the connected network so it doesn't appear in the list, unless we are currently trying to connect to it
|
if (parts.length < offset + 3) continue
|
||||||
|
var isConnected = parts[offset] === "1"
|
||||||
|
var ssid = parts[offset + 1]
|
||||||
|
if (isConnected && ssid !== root.actionSsid) continue // Skip the connected network so it doesn't appear in the list, unless we are currently trying to connect to it
|
||||||
|
var isKnown = knownNetworks[ssid] === true
|
||||||
|
if (parts.length > offset + 4) isKnown = isKnown || parts[offset + 4] === "1"
|
||||||
|
|
||||||
nets.push({
|
nets.push({
|
||||||
connected: false,
|
connected: isConnected,
|
||||||
ssid: parts[1],
|
known: isKnown,
|
||||||
signal: parseInt(parts[2], 10) || 0,
|
ssid: ssid,
|
||||||
security: parts[3] || ""
|
signal: parseInt(parts[offset + 2], 10) || 0,
|
||||||
|
security: parts[offset + 3] || ""
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
nets.sort(function(a, b) {
|
nets.sort(function(a, b) {
|
||||||
@@ -1017,14 +1047,16 @@ fi
|
|||||||
// A single Wi-Fi network entry. Collapses to a one-line pill normally;
|
// A single Wi-Fi network entry. Collapses to a one-line pill normally;
|
||||||
// expands inline to a passphrase prompt when the user picks a protected
|
// expands inline to a passphrase prompt when the user picks a protected
|
||||||
// network we don't have credentials for. Clicking a connected row
|
// network we don't have credentials for. Clicking a connected row
|
||||||
// disconnects; the X button on a connected row forgets the network.
|
// disconnects; the X button on any saved/connected row forgets it.
|
||||||
component NetworkRow: CursorSurface {
|
component NetworkRow: CursorSurface {
|
||||||
id: row
|
id: row
|
||||||
required property var net
|
required property var net
|
||||||
required property int index
|
required property int index
|
||||||
|
|
||||||
readonly property bool isConnected: net && net.connected
|
readonly property bool isConnected: net && net.connected
|
||||||
|
readonly property bool isKnown: !!(net && net.known)
|
||||||
readonly property bool isProtected: root.isProtected(net ? net.security : "")
|
readonly property bool isProtected: root.isProtected(net ? net.security : "")
|
||||||
|
readonly property bool canForget: isConnected || isKnown
|
||||||
readonly property bool isSelected: root.focusSection === "wifi" && root.selectedIndex === index
|
readonly property bool isSelected: root.focusSection === "wifi" && root.selectedIndex === index
|
||||||
|
|
||||||
hasCursor: root.cursorActive && isSelected
|
hasCursor: root.cursorActive && isSelected
|
||||||
@@ -1085,12 +1117,12 @@ fi
|
|||||||
root.disconnect(row.net.ssid)
|
root.disconnect(row.net.ssid)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (row.isProtected) {
|
if (row.isProtected && !row.isKnown) {
|
||||||
// Known protected network: iwd has the passphrase, just connect.
|
// Unknown protected network: probe iwd before expanding the inline
|
||||||
// Otherwise expand the inline password prompt for this row. Stash
|
// password prompt for this row. Stash the SSID as a string — if we
|
||||||
// the SSID as a string — if we held a reference to the row
|
// held a reference to the row delegate it could be destroyed by a
|
||||||
// delegate it could be destroyed by a model refresh, and a rapid
|
// model refresh, and a rapid second click would overwrite it and
|
||||||
// second click would overwrite it and misroute the first result.
|
// misroute the first result.
|
||||||
var quotedSsid = root.bar.shellQuote(row.net.ssid)
|
var quotedSsid = root.bar.shellQuote(row.net.ssid)
|
||||||
knownCheck.targetSsid = row.net.ssid
|
knownCheck.targetSsid = row.net.ssid
|
||||||
knownCheck.command = ["bash", "-c", `
|
knownCheck.command = ["bash", "-c", `
|
||||||
@@ -1131,9 +1163,10 @@ iwctl known-networks list 2>/dev/null \\
|
|||||||
|
|
||||||
PanelActionButton {
|
PanelActionButton {
|
||||||
id: forgetBtn
|
id: forgetBtn
|
||||||
anchors.right: parent.right
|
anchors.right: lockIndicator.visible ? lockIndicator.left : parent.right
|
||||||
|
anchors.rightMargin: lockIndicator.visible ? Style.space(4) : 0
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
visible: row.isConnected
|
visible: row.canForget
|
||||||
enabled: !root.busy
|
enabled: !root.busy
|
||||||
iconText: ""
|
iconText: ""
|
||||||
tooltipText: "Forget network"
|
tooltipText: "Forget network"
|
||||||
@@ -1144,11 +1177,8 @@ iwctl known-networks list 2>/dev/null \\
|
|||||||
onClicked: if (row.net) root.forget(row.net.ssid)
|
onClicked: if (row.net) root.forget(row.net.ssid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shows a lock glyph on the right for protected networks that
|
// Shows a lock glyph for protected disconnected networks at the far
|
||||||
// aren't currently connected. Once connected, the forget X takes
|
// right, with the forget X to its left when the network is saved.
|
||||||
// its place (and 'protected' is implied by the fact we're on it).
|
|
||||||
// Same action-sized right-anchored centered geometry as forgetBtn so
|
|
||||||
// the glyph centers line up across rows.
|
|
||||||
Text {
|
Text {
|
||||||
id: lockIndicator
|
id: lockIndicator
|
||||||
visible: row.isProtected && !row.isConnected
|
visible: row.isProtected && !row.isConnected
|
||||||
@@ -1182,11 +1212,11 @@ iwctl known-networks list 2>/dev/null \\
|
|||||||
width: parent.width
|
width: parent.width
|
||||||
}
|
}
|
||||||
Text {
|
Text {
|
||||||
// Signal strength is conveyed by the wifi-bars icon and a lock
|
// Signal strength is conveyed by the wifi-bars icon and the
|
||||||
// glyph on the right denotes protected networks, so the second
|
// right-edge glyph/buttons carry protection or forget affordances,
|
||||||
// line only carries action status (Connecting…, Connected,
|
// so the second line only carries action status (Connecting…,
|
||||||
// Failed, etc.). Collapses to zero height when empty so rows
|
// Connected, Failed, etc.). Collapses to zero height when empty
|
||||||
// without status keep a tight one-line look.
|
// so rows without status keep a tight one-line look.
|
||||||
text: row.statusText
|
text: row.statusText
|
||||||
visible: row.statusText !== ""
|
visible: row.statusText !== ""
|
||||||
height: visible ? implicitHeight : 0
|
height: visible ? implicitHeight : 0
|
||||||
|
|||||||
Reference in New Issue
Block a user