Created toggle for hotspot in admin settings. User needs sudo privileges.

This commit is contained in:
Roland 2022-02-04 09:41:08 -07:00
parent bc22fb6a6c
commit f27e9fdf63
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
8 changed files with 398 additions and 6 deletions

View file

@ -1,5 +1,14 @@
import {useEffect, useState} from "react";
import {fetchDomains, filesSearch, getFiles, getVersion, searchArchives, searchVideos} from "../api";
import {
fetchDomains,
filesSearch,
getDevices,
getFiles,
getVersion,
searchArchives,
searchVideos,
setHotspot
} from "../api";
import {useHistory} from "react-router-dom";
export const useSearchParam = (key, defaultValue = null) => {
@ -178,3 +187,27 @@ export const useBrowseFiles = () => {
return {browseFiles, openFolders, setOpenFolders, fetchFiles};
}
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');
}
}
useEffect(() => {
fetchDevices();
});
const localSetHotspot = async (on) => {
setOn(null);
setHotspot(on);
fetchDevices();
}
return {on, setOn, setHotspot: localSetHotspot};
}