Spinning when scanning

This commit is contained in:
David Heinemeier Hansson
2026-05-18 20:47:38 +02:00
parent c26cf49f7d
commit c517997922
3 changed files with 45 additions and 37 deletions
+11 -1
View File
@@ -18,6 +18,7 @@ Rectangle {
property real fontSize: 12 property real fontSize: 12
property real iconSize: 14 property real iconSize: 14
property real iconRotation: 0 property real iconRotation: 0
property bool iconSpinning: false
property real horizontalPadding: 10 property real horizontalPadding: 10
property real verticalPadding: 6 property real verticalPadding: 6
property bool active: false property bool active: false
@@ -112,14 +113,23 @@ Rectangle {
spacing: 8 spacing: 8
Text { Text {
id: iconLabel
visible: root.iconText !== "" visible: root.iconText !== ""
text: root.iconText text: root.iconText
color: root.foreground color: root.foreground
font.family: root.fontFamily font.family: root.fontFamily
font.pixelSize: root.iconSize font.pixelSize: root.iconSize
rotation: root.iconRotation rotation: root.iconSpinning ? 0 : root.iconRotation
transformOrigin: Item.Center transformOrigin: Item.Center
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
RotationAnimation on rotation {
from: 0
to: 360
duration: 900
loops: Animation.Infinite
running: root.iconSpinning
}
} }
Text { Text {
+1 -10
View File
@@ -415,21 +415,12 @@ Item {
HeaderPill { HeaderPill {
pillIndex: 0 pillIndex: 0
property real scanRotation: 0
iconText: "󰑐" iconText: "󰑐"
iconRotation: root.adapter && root.adapter.discovering ? scanRotation : 0 iconSpinning: root.adapter && root.adapter.discovering
tooltipText: !root.adapter ? "" : !root.adapter.enabled ? "Bluetooth is off" tooltipText: !root.adapter ? "" : !root.adapter.enabled ? "Bluetooth is off"
: root.adapter.discovering ? "Stop scanning" : "Scan for devices" : root.adapter.discovering ? "Stop scanning" : "Scan for devices"
pillEnabled: root.adapter !== null && root.adapter.enabled pillEnabled: root.adapter !== null && root.adapter.enabled
onActivated: if (root.adapter) root.adapter.discovering = !root.adapter.discovering onActivated: if (root.adapter) root.adapter.discovering = !root.adapter.discovering
NumberAnimation on scanRotation {
from: 0
to: 360
duration: 900
loops: Animation.Infinite
running: root.adapter && root.adapter.discovering
}
} }
HeaderPill { HeaderPill {
+33 -26
View File
@@ -77,7 +77,7 @@ Item {
// — OnDemand only grants focus on click/hover. // — OnDemand only grants focus on click/hover.
onPopupOpenChanged: { onPopupOpenChanged: {
if (popupOpen) { if (popupOpen) {
refresh() refresh(true)
selectedIndex = wifiNetworks.length > 0 ? 0 : -1 selectedIndex = wifiNetworks.length > 0 ? 0 : -1
focusSection = "dns" focusSection = "dns"
var idx = dnsProviders.indexOf(dnsProvider) var idx = dnsProviders.indexOf(dnsProvider)
@@ -215,7 +215,8 @@ iwctl known-networks list 2>/dev/null \\
return "󰤮" return "󰤮"
} }
function refresh() { function refresh(scanWifi) {
if (scanWifi === undefined) scanWifi = false
if (!detailsProc.running) detailsProc.running = true if (!detailsProc.running) detailsProc.running = true
if (!dnsProc.running) { if (!dnsProc.running) {
dnsProc.command = ["bash", "-lc", root.dnsCommand("")] dnsProc.command = ["bash", "-lc", root.dnsCommand("")]
@@ -223,10 +224,38 @@ iwctl known-networks list 2>/dev/null \\
} }
if (!wifiProc.running) { if (!wifiProc.running) {
scanning = true scanning = true
wifiProc.command = ["bash", "-c", root.wifiScanScript(scanWifi)]
wifiProc.running = true wifiProc.running = true
} }
} }
function wifiScanScript(scanWifi) {
return `
station=$(iwctl station list 2>/dev/null | sed -e 's/\\x1b\\[[0-9;]*m//g' | awk '/^[[:space:]]*wl/ { print $1; exit }')
[[ -z $station ]] && exit 0
echo STATION_AVAILABLE
${scanWifi ? 'iwctl station "$station" scan >/dev/null 2>&1 || true' : ''}
iwctl station "$station" get-networks rssi-dbms 2>/dev/null \\
| sed -e 's/\\x1b\\[[0-9;]*m//g' \\
| awk '
NR <= 4 { next }
/^[[:space:]]*$/ { next }
{
connected = (substr($0, 1, 4) ~ />/) ? 1 : 0
line = $0
sub(/^[[:space:]]*>?[[:space:]]+/, "", line)
sub(/[[:space:]]+$/, "", line)
n = split(line, parts, /[[:space:]]{2,}/)
if (n < 3) next
ssid = parts[1]
security = parts[n-1]
dbm = parts[n] / 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
}'
`
}
function formatSpeed(mbps) { function formatSpeed(mbps) {
var v = parseInt(mbps, 10) var v = parseInt(mbps, 10)
if (!v || v < 0) return "" if (!v || v < 0) return ""
@@ -454,29 +483,6 @@ fi
// iwctl's table layout starts each row with one, which breaks naive parsing. // iwctl's table layout starts each row with one, which breaks naive parsing.
Process { Process {
id: wifiProc id: wifiProc
command: ["bash", "-c", `
station=$(iwctl station list 2>/dev/null | sed -e 's/\\x1b\\[[0-9;]*m//g' | awk '/^[[:space:]]*wl/ { print $1; exit }')
[[ -z $station ]] && exit 0
echo STATION_AVAILABLE
iwctl station "$station" get-networks rssi-dbms 2>/dev/null \\
| sed -e 's/\\x1b\\[[0-9;]*m//g' \\
| awk '
NR <= 4 { next }
/^[[:space:]]*$/ { next }
{
connected = (substr($0, 1, 4) ~ />/) ? 1 : 0
line = $0
sub(/^[[:space:]]*>?[[:space:]]+/, "", line)
sub(/[[:space:]]+$/, "", line)
n = split(line, parts, /[[:space:]]{2,}/)
if (n < 3) next
ssid = parts[1]
security = parts[n-1]
dbm = parts[n] / 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
}'
`]
stdout: StdioCollector { stdout: StdioCollector {
waitForEnd: true waitForEnd: true
onStreamFinished: root.updateWifi(text) onStreamFinished: root.updateWifi(text)
@@ -701,6 +707,7 @@ iwctl station "$station" get-networks rssi-dbms 2>/dev/null \\
anchors.right: parent.right anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
iconText: "󰑐" iconText: "󰑐"
iconSpinning: root.scanning
tooltipText: "Refresh" tooltipText: "Refresh"
tooltipBackground: root.bar.background tooltipBackground: root.bar.background
tooltipForeground: root.bar.foreground tooltipForeground: root.bar.foreground
@@ -709,7 +716,7 @@ iwctl station "$station" get-networks rssi-dbms 2>/dev/null \\
verticalPadding: 4 verticalPadding: 4
iconSize: 14 iconSize: 14
active: root.scanning active: root.scanning
onClicked: root.refresh() onClicked: root.refresh(true)
} }
} }