Refusing to start hotspot if Wifi device is in use.

This commit is contained in:
Roland 2024-07-31 12:41:53 -06:00
parent a068273beb
commit e72d461461
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
4 changed files with 90 additions and 18 deletions

View file

@ -1042,30 +1042,59 @@ export function UnsupportedModal(header, message, icon) {
}
export function HotspotStatusIcon() {
const {on, setHotspot, dockerized} = useHotspot();
const {modal, doOpen} = UnsupportedModal('Unsupported', 'You cannot toggle the hotspot on this machine.');
const [confirmOpen, setConfirmOpen] = React.useState(false);
const {on, inUse, setHotspot, dockerized, hotspotSsid} = useHotspot();
const {modal: unsupportedModal, doOpen: openUnsupportedModal} =
UnsupportedModal('Unsupported', 'You cannot toggle the hotspot on this machine.');
const [disableHotspotOpen, setDisableHotspotOpen] = React.useState(false);
const [inUseOpen, setInUseOpen] = React.useState(false);
const handleConfirm = (e) => {
const handleConfirmDisable = (e) => {
if (e) {
e.preventDefault()
}
setConfirmOpen(false);
setDisableHotspotOpen(false);
setHotspot(false);
}
if (dockerized === false && on === true) {
const handleConfirmInUse = (e) => {
if (e) {
e.preventDefault()
}
setInUseOpen(false);
setHotspot(true);
}
if (inUse === true) {
const content = hotspotSsid ? `Wifi device is in use for ${hotspotSsid}. Disconnect and enable hotspot?`
: 'Wifi device is in use. Disconnect and enable hotspot?'
return <>
<Confirm open={inUseOpen}
onCancel={() => setInUseOpen(false)}
onClose={() => setInUseOpen(false)}
onConfirm={handleConfirmInUse}
header='Wifi is in-use'
content={content}
confirmButton='Enable Hotspot'
/>
<a href='#' onClick={() => setInUseOpen(true)}>
<IconGroup size='large'>
<Icon name='wifi' disabled/>
<Icon corner name='exclamation'/>
</IconGroup>
</a>
</>
} else if (dockerized === false && on === true) {
return <>
<Confirm
open={confirmOpen}
onCancel={() => setConfirmOpen(false)}
onClose={() => setConfirmOpen(false)}
onConfirm={handleConfirm}
open={disableHotspotOpen}
onCancel={() => setDisableHotspotOpen(false)}
onClose={() => setDisableHotspotOpen(false)}
onConfirm={handleConfirmDisable}
header='Disable the hotspot'
content='You will be disconnected when using the hotspot. Are you sure?'
confirmButton='Disable'
/>
<a href='#' onClick={() => setConfirmOpen(true)}>
<a href='#' onClick={() => setDisableHotspotOpen(true)}>
<IconGroup size='large'>
<Icon name='wifi' disabled={on !== true}/>
{on === false && <Icon corner name='x'/>}
@ -1084,13 +1113,13 @@ export function HotspotStatusIcon() {
// Hotspot is not available, or, status has not yet been fetched.
return <>
<a href='#' onClick={doOpen}>
<a href='#' onClick={openUnsupportedModal}>
<IconGroup size='large'>
<Icon name='wifi' disabled/>
<Icon corner name='question'/>
</IconGroup>
</a>
{modal}
{unsupportedModal}
</>
}

View file

@ -623,17 +623,23 @@ export const useFilesProgressInterval = () => {
export const useHotspot = () => {
const [on, setOn] = useState(null);
const [inUse, setInUse] = useState(false);
const {status} = useContext(StatusContext);
// Hotspot is unsupported on Docker.
const {dockerized} = status;
const {dockerized, hotspot_ssid} = status;
useEffect(() => {
if (status && status['hotspot_status']) {
const {hotspot_status} = status;
if (hotspot_status === 'connected') {
setOn(true);
setInUse(false);
} else if (hotspot_status === 'in_use') {
setInUse(true);
setOn(false);
} else if (hotspot_status === 'disconnected' || hotspot_status === 'unavailable') {
setOn(false);
setInUse(false);
} else {
setOn(null);
}
@ -645,7 +651,7 @@ export const useHotspot = () => {
await setHotspot(on);
}
return {on, setOn, setHotspot: localSetHotspot, dockerized};
return {on, inUse, hotspotSsid: hotspot_ssid, setOn, setHotspot: localSetHotspot, dockerized};
}
export const useDownloads = () => {