diff --git a/bin/omarchy-network-qr b/bin/omarchy-network-qr index 9502c25c..fb1c6696 100755 --- a/bin/omarchy-network-qr +++ b/bin/omarchy-network-qr @@ -22,7 +22,9 @@ if [[ -z $interface ]]; then # menu's visibility gate describe. Fall back to the first connected Wi-Fi # device. nmcli localizes state names, so pin the locale, and the prefix # match accepts states like "connected (externally)". - route_device=$(ip route get 1.1.1.1 2>/dev/null | awk '{ for (i = 1; i <= NF; i++) if ($i == "dev") { print $(i + 1); exit } }') + if ! route_device=$(ip route get 1.1.1.1 2>/dev/null | awk '{ for (i = 1; i <= NF; i++) if ($i == "dev") { print $(i + 1); exit } }'); then + route_device="" + fi if [[ -n $route_device && -d /sys/class/net/$route_device/wireless ]]; then interface=$route_device else diff --git a/test/shell.d/network-qr-test.sh b/test/shell.d/network-qr-test.sh index 071950a9..7e54ad43 100644 --- a/test/shell.d/network-qr-test.sh +++ b/test/shell.d/network-qr-test.sh @@ -7,10 +7,12 @@ source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT mkdir -p "$tmp/bin" +export QR_ROUTE_EXIT=0 # Loopback is never wireless, so exercise the connected-Wi-Fi fallback. cat >"$tmp/bin/ip" <<'EOF' #!/bin/bash +[[ $QR_ROUTE_EXIT == "0" ]] || exit "$QR_ROUTE_EXIT" printf '1.1.1.1 dev lo\n' EOF @@ -93,6 +95,12 @@ run_success_case \ 'WIFI:T:WPA;S:Cafe Detected;P:secret;;' \ --meta +QR_ROUTE_EXIT=2 run_success_case \ + "network QR helper detects Wi-Fi when route lookup fails" \ + $'Cafe No Route\nwpa-psk\nsecret\nno\n' \ + 'WIFI:T:WPA;S:Cafe No Route;P:secret;;' \ + --meta + run_success_case \ "network QR helper supports open networks" \ $'Cafe Open\nnone\n\nno\n' \