diff --git a/core/openwrt/src/wan.rs b/core/openwrt/src/wan.rs index 11603170..fd63014b 100644 --- a/core/openwrt/src/wan.rs +++ b/core/openwrt/src/wan.rs @@ -143,7 +143,7 @@ pub fn get_wan_status(router: &Router) -> serde_json::Value { if [ \"$n\" = \"wan\" ]; then \ uci get firewall.@zone[$i].masq 2>/dev/null; break; \ fi; done"; - router.run_ok(script).unwrap_or_default().trim().to_string() == "1" + router.run_ok(script).unwrap_or_default().trim() == "1" }; info!("[{}] WAN status: configured={} ssid={:?} assoc={:?} sta_iface={:?} sta_state={:?} ip={:?} lan={} masq={}", diff --git a/core/openwrt/src/wifi_scan.rs b/core/openwrt/src/wifi_scan.rs index d16f0170..1278da74 100644 --- a/core/openwrt/src/wifi_scan.rs +++ b/core/openwrt/src/wifi_scan.rs @@ -72,7 +72,9 @@ fn parse_mtk_site_survey(output: &str) -> Result> { encryption: normalize_encryption(security), }); } - networks.sort_by(|a, b| b.signal.cmp(&a.signal)); + // Strongest signal first. `Reverse` keeps this a stable descending sort, + // identical in ordering (including ties) to the previous `sort_by` comparator. + networks.sort_by_key(|n| std::cmp::Reverse(n.signal)); Ok(networks) } @@ -153,7 +155,6 @@ fn parse_iwinfo_scan(output: &str) -> Result> { } else if line.contains("Channel:") && !line.starts_with("Encryption") { if let Some(ch_part) = line.split("Channel:").nth(1) { n.channel = ch_part - .trim() .split_whitespace() .next() .and_then(|s| s.parse().ok()) @@ -174,7 +175,9 @@ fn parse_iwinfo_scan(output: &str) -> Result> { } } - networks.sort_by(|a, b| b.signal.cmp(&a.signal)); + // Strongest signal first. `Reverse` keeps this a stable descending sort, + // identical in ordering (including ties) to the previous `sort_by` comparator. + networks.sort_by_key(|n| std::cmp::Reverse(n.signal)); Ok(networks) }