wifi: omit empty info snapshot and tidy up

- Info.WiFi uses json "wf" with omitempty so systems without Wi-Fi no
  longer store/broadcast "wifi":null
- move osascript exec into wifi_darwin.go; drop unused commandRunner
- share strongest-connection logic between table cell and sorting
- trim agent/wifi README
This commit is contained in:
henrygd
2026-09-25 18:42:33 -04:00
parent 16e3fbadce
commit 24792aa24f
9 changed files with 37 additions and 72 deletions

View File

@@ -3,14 +3,22 @@ import type { SystemRecord, WiFi } from "@/types"
// Current system info is independent of the selected historical chart window.
// No fallback to history: missing data, disconnect and offline all hide the panel.
export function connectedWiFi(system: Pick<SystemRecord, "status" | "info">): [string, WiFi][] {
return system.status === "up" ? Object.entries(system.info?.wifi ?? {}).sort(([a], [b]) => a.localeCompare(b)) : []
return system.status === "up" ? Object.entries(system.info?.wf ?? {}).sort(([a], [b]) => a.localeCompare(b)) : []
}
/** Strongest connection by RSSI, falling back to the first when none report a signal. */
export function strongestWiFi(connections: [string, WiFi][]): [string, WiFi] | undefined {
let strongest = connections[0]
for (const connection of connections) {
if ((connection[1].r ?? -Infinity) > (strongest[1].r ?? -Infinity)) {
strongest = connection
}
}
return strongest
}
export function strongestWiFiSignal(system: Pick<SystemRecord, "status" | "info">): number | undefined {
const signals = connectedWiFi(system)
.map(([, wifi]) => wifi.r)
.filter((signal): signal is number => signal !== undefined && Number.isFinite(signal))
return signals.length ? Math.max(...signals) : undefined
return strongestWiFi(connectedWiFi(system))?.[1].r
}
export function wifiColor(id: string): string {