Repository navigation
Settings Wi-Fi + Bluetooth panels: refresh state every 10 s while the panel is open (live-surfaces rule) #4011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ### Changed | ||
| - Wi-Fi and Bluetooth settings panels now auto-refresh every 10 seconds while open, showing live device/AP changes without reopening Settings. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,10 +7,9 @@ export function BluetoothPanel() { | |
| const [devices, setDevices] = useState<{ path: string; address: string; name: string | null; paired: boolean; connected: boolean; trusted: boolean }[]>([]); | ||
| const [error, setError] = useState<string | null>(null); | ||
| const mounted = useRef(true); | ||
| useEffect(() => () => { mounted.current = false; }, []); | ||
|
|
||
| useEffect(() => { | ||
| (async () => { | ||
| const load = async () => { | ||
| try { | ||
| const res = await fetch("/api/hardware/bluetooth", { credentials: "include" }); | ||
| const body = await res.json().catch(() => null); | ||
|
|
@@ -26,10 +25,17 @@ export function BluetoothPanel() { | |
| if (Array.isArray(body.devices)) { | ||
| setDevices(body.devices); | ||
| } | ||
| setError(null); | ||
| } catch { | ||
| if (mounted.current) setError("Could not reach taOS."); | ||
| } | ||
| })(); | ||
| }; | ||
| load(); | ||
| const id = setInterval(load, 10_000); | ||
| return () => { | ||
| mounted.current = false; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| clearInterval(id); | ||
| }; | ||
| }, []); | ||
|
|
||
| return ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,10 +8,9 @@ export function WifiPanel() { | |
| const [accessPoints, setAccessPoints] = useState<{ ssid: string; strength: number; frequency: number; secured: boolean; active: boolean }[]>([]); | ||
| const [error, setError] = useState<string | null>(null); | ||
| const mounted = useRef(true); | ||
| useEffect(() => () => { mounted.current = false; }, []); | ||
|
|
||
| useEffect(() => { | ||
| (async () => { | ||
| const load = async () => { | ||
| try { | ||
| const res = await fetch("/api/hardware/wifi", { credentials: "include" }); | ||
| const body = await res.json().catch(() => null); | ||
|
|
@@ -25,10 +24,17 @@ export function WifiPanel() { | |
| if (body.available && body.wifi_enabled && Array.isArray(body.access_points)) { | ||
| setAccessPoints(body.access_points); | ||
| } | ||
| setError(null); | ||
| } catch { | ||
| if (mounted.current) setError("Could not reach taOS."); | ||
| } | ||
| })(); | ||
| }; | ||
| load(); | ||
| const id = setInterval(load, 10_000); | ||
|
Comment on lines
30
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return () => { | ||
| mounted.current = false; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| clearInterval(id); | ||
| }; | ||
| }, []); | ||
|
|
||
| return ( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore stale Bluetooth loads.
setInterval(load, 10_000)can start a second request before the first completes. The requests update panel state in completion order, so an older response can overwrite newer Bluetooth data. Track the latest request independently of the unmount guard.Suggested fix