Hotspot can be toggled in UI. Tested on RPi.

This commit is contained in:
Roland 2022-02-04 16:05:19 -07:00
parent d935da95f2
commit 41e89843bf
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
5 changed files with 121 additions and 223 deletions

View file

@ -2,7 +2,7 @@ import {useEffect, useState} from "react";
import {
fetchDomains,
filesSearch,
getDevices,
getHotspotStatus,
getDownloaders,
getFiles,
getVersion,
@ -194,22 +194,20 @@ export const useBrowseFiles = () => {
export const useHotspot = () => {
const [on, setOn] = useState(null);
const fetchDevices = async () => {
const devices = await getDevices();
if (devices && devices['wlan0']) {
let wlan0 = devices['wlan0'];
setOn(wlan0['connection'] === 'connected');
}
const fetchHotspotStatus = async () => {
const status = await getHotspotStatus();
// Wi-Fi can be: connected, disconnected, unavailable.
setOn(status === 'connected');
}
useEffect(() => {
fetchDevices();
});
fetchHotspotStatus();
}, []);
const localSetHotspot = async (on) => {
setOn(null);
await setHotspot(on);
await fetchDevices();
await fetchHotspotStatus();
}
return {on, setOn, setHotspot: localSetHotspot};