import React, {Component} from "react"; import { Alert, Backdrop, Box, Button, CircularProgress, Fade, FormControl, InputLabel, LinearProgress, MenuItem, Modal, Select, SelectChangeEvent, Stack, TextField, Typography } from "@mui/material"; import WifiPasswordIcon from "@mui/icons-material/WifiPassword"; import WifiIcon from "@mui/icons-material/Wifi"; import {IPCAnswer, WiFiNetwork} from "../RawConstants"; interface WiFiState { open: boolean, currentSelection: string, selectedSecured: boolean, foundWiFis: WiFiNetwork[], scanning: boolean, status: status, password: string, } type status = "NONE" | "SELECTION_FAILURE" | "CONNECTING" | "PASSWORD_NEEDED" | "FAILURE" | "CONNECTED" | 'SCAN_FAILURE'; export default class WiFi extends Component<{}, WiFiState> { constructor(props: {}) { super(props); this.state = { open: true, currentSelection: "pleaseSelect", selectedSecured: false, foundWiFis: [], scanning: false, status: "NONE", password: "", }; } componentDidMount() { this.scanWifi(); } style = { position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)', width: '50%', bgcolor: 'background.paper', border: '2px solid #000', boxShadow: 24, p: 4, }; scanWifi = () => { this.setState((prevState) => ({ ...prevState, //currentSelection: "pleaseSelect", //foundWiFis: [], scanning: true, })); window.api.request('WIFI_SCAN', {}).then((answer: IPCAnswer) => { if(answer.status) this.setState((prevState) => ({ ...prevState, foundWiFis: answer.data as WiFiNetwork[], scanning: false })); else this.setState((prevState) => ({ ...prevState, status: "SCAN_FAILURE", scanning: false })); }); } handleClose = () => { window.app.toggleWiFiSettings(false); } handleConnect = () => { if(this.state.currentSelection == "pleaseSelect") { return this.setState((prevState) => ({ ...prevState, status: "SELECTION_FAILURE" })); } this.setState((prevState) => ({ ...prevState, status: "CONNECTING" })); window.api.request('WIFI_CONNECT', {data: {ssid: this.state.currentSelection, psk: this.state.password}}).then((answer: IPCAnswer) => { this.setState((prevState) => ({ ...prevState, status: answer.status ? "CONNECTED" : "FAILURE" })); }) } onChange = (event: SelectChangeEvent) => { let isSecured = false; for(let x of this.state.foundWiFis) { if(x.ssid == event.target.value) isSecured = x.isSecured; } this.setState((prevState) => ({ ...prevState, currentSelection: event.target.value, selectedSecured: isSecured, })); } render() { return {(this.state.scanning||this.state.status == "CONNECTING") && } WiFi Verbindungsmanager {this.state.status == "NONE" && "Bitte wählen Sie eins der folgenden Netzwerke aus"} {this.state.status == "CONNECTING" && "Verbinden..." } {this.state.status == "CONNECTED" && "Verbunden!" } {this.state.status == "SCAN_FAILURE" && "Das Scannen ist fehlgeschlagen. - Möglicherweise fehlen Berechtigungen, um Netzwerke zu scannen, oder es befindet sich kein WLAN-Interface auf diesem Gerät." } {this.state.status == "FAILURE" && "Verbindungsfehler!" } {this.state.status == "SELECTION_FAILURE" && "Bitte zunächst ein Netzwerk auswählen!" }
WiFi this.setState(prev => ({ ...prev, password: evt.target.value }))} label="Passwort" disabled={this.state.scanning || !this.state.selectedSecured} variant="outlined" />

} }