mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 03:46:29 -05:00
Hotspot can be toggled in UI. Tested on RPi.
This commit is contained in:
parent
d935da95f2
commit
41e89843bf
5 changed files with 121 additions and 223 deletions
|
|
@ -437,16 +437,23 @@ export async function getVersion() {
|
|||
return data['version'];
|
||||
}
|
||||
|
||||
export async function getDevices() {
|
||||
export async function getHotspotStatus() {
|
||||
let response = await apiGet(`${API_URI}/hotspot`);
|
||||
if (response.status === 200) {
|
||||
let {devices} = await response.json();
|
||||
return devices;
|
||||
let {status} = await response.json();
|
||||
return status;
|
||||
} else {
|
||||
let code = (await response.json())['code'];
|
||||
if (response.status === 400 && code === 34) {
|
||||
// Must not be running on a RPi. Don't warn the user.
|
||||
return null;
|
||||
} else {
|
||||
toast({
|
||||
type: 'error',
|
||||
title: "Can't get Hotspot status",
|
||||
description: 'Failed to get Hotspot status. Check client and server logs.',
|
||||
time: 5000,
|
||||
});
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
@ -470,6 +477,13 @@ export async function setHotspot(on) {
|
|||
description: 'Hotspot is only supported on a Raspberry Pi!',
|
||||
time: 5000,
|
||||
});
|
||||
} else {
|
||||
toast({
|
||||
type: 'error',
|
||||
title: 'Error!',
|
||||
description: 'Could not modify hotspot. See server logs.',
|
||||
time: 5000,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue