mirror of
https://github.com/henrygd/beszel.git
synced 2026-09-26 11:27:47 +02:00
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:
@@ -38,7 +38,7 @@ import {
|
||||
secondsToUptimeString,
|
||||
} from "@/lib/utils"
|
||||
import { batteryStateTranslations } from "@/lib/i18n"
|
||||
import { connectedWiFi, strongestWiFiSignal } from "@/lib/wifi"
|
||||
import { connectedWiFi, strongestWiFi, strongestWiFiSignal } from "@/lib/wifi"
|
||||
import type { SystemRecord } from "@/types"
|
||||
import { SystemDialog } from "../add-system"
|
||||
import AlertButton from "../alerts/alert-button"
|
||||
@@ -358,12 +358,10 @@ export function SystemsTableColumns(viewMode: "table" | "grid"): ColumnDef<Syste
|
||||
sortUndefined: "last",
|
||||
cell(info) {
|
||||
const connections = connectedWiFi(info.row.original)
|
||||
if (!connections.length) {
|
||||
const strongest = strongestWiFi(connections)
|
||||
if (!strongest) {
|
||||
return null
|
||||
}
|
||||
const strongest = connections.reduce((best, current) =>
|
||||
(current[1].r ?? Number.NEGATIVE_INFINITY) > (best[1].r ?? Number.NEGATIVE_INFINITY) ? current : best
|
||||
)
|
||||
const displayedConnections = viewMode === "table" ? [strongest] : connections
|
||||
const title = connections
|
||||
.map(([id, wifi]) => `${id}${wifi.s ? ` (${wifi.s})` : ""}: ${wifi.r === undefined ? "—" : `${wifi.r} dBm`}`)
|
||||
|
||||
@@ -2,7 +2,7 @@ import { expect, test } from "bun:test"
|
||||
import { connectedWiFi, strongestWiFiSignal, wifiColor } from "./wifi"
|
||||
import type { SystemInfo } from "@/types"
|
||||
|
||||
const system = (wifi?: SystemInfo["wifi"], status: "up" | "down" = "up") => ({ status, info: { wifi } as SystemInfo })
|
||||
const system = (wf?: SystemInfo["wf"], status: "up" | "down" = "up") => ({ status, info: { wf } as SystemInfo })
|
||||
|
||||
test("current state gates panel, not retained history", () => {
|
||||
expect(connectedWiFi(system())).toEqual([])
|
||||
|
||||
@@ -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 {
|
||||
|
||||
3
internal/site/src/types.d.ts
vendored
3
internal/site/src/types.d.ts
vendored
@@ -39,7 +39,8 @@ export interface WiFi {
|
||||
}
|
||||
|
||||
export interface SystemInfo {
|
||||
wifi?: Record<string, WiFi> | null
|
||||
/** connected Wi-Fi interfaces */
|
||||
wf?: Record<string, WiFi>
|
||||
/** hostname */
|
||||
h: string
|
||||
/** kernel **/
|
||||
|
||||
Reference in New Issue
Block a user