Skip to content

Commit

Permalink
Merge pull request #290 from justinlampley/WIFIFlashingWarning
Browse files Browse the repository at this point in the history
Warn about unplugging power to soon when flashing via WIFI
  • Loading branch information
jurgelenas authored Mar 10, 2022
2 parents e92632b + 11b1963 commit 68de70e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 11 deletions.
37 changes: 37 additions & 0 deletions src/ui/components/ShowAfterTimeout/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { FunctionComponent, useEffect, useRef, useState } from 'react';

interface ShowAfterTimeoutProps {
timeout: number;
active: boolean;
}

const ShowAfterTimeout: FunctionComponent<ShowAfterTimeoutProps> = ({
timeout,
active,
...props
}) => {
const [visible, setVisible] = useState<boolean>(false);
const activeRef = useRef(active);
activeRef.current = active;
const timeoutRef = useRef<number | null>(null);
useEffect(() => {
if (activeRef.current) {
timeoutRef.current = window.setTimeout(() => {
setVisible(true);
}, timeout);
} else {
setVisible(false);
if (timeoutRef.current !== null) {
clearTimeout(timeoutRef.current);
}
}
return () => {
if (timeoutRef.current !== null) {
clearTimeout(timeoutRef.current);
}
};
}, [active, timeout]);
return <>{visible && props.children}</>;
};

export default ShowAfterTimeout;
45 changes: 34 additions & 11 deletions src/ui/views/ConfiguratorView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import WifiDeviceSelect from '../../components/WifiDeviceSelect';
import WifiDeviceList from '../../components/WifiDeviceList';
import GitRepository from '../../models/GitRepository';
import ShowTimeoutAlerts from '../../components/ShowTimeoutAlerts';
import ShowAfterTimeout from '../../components/ShowAfterTimeout';
import useAppState from '../../hooks/useAppState';
import AppStatus from '../../models/enum/AppStatus';
import MainLayout from '../../layouts/MainLayout';
Expand Down Expand Up @@ -1024,9 +1025,39 @@ const ConfiguratorView: FunctionComponent<ConfiguratorViewProps> = (props) => {
<CardTitle icon={<SettingsIcon />} title="Result" />
<Divider />
<CardContent>
<Box sx={styles.buildNotification}>
<BuildResponse response={response?.buildFlashFirmware} />
</Box>
{response?.buildFlashFirmware?.success &&
currentJobType === BuildJobType.BuildAndFlash &&
deviceTarget?.flashingMethod === FlashingMethod.WIFI && (
<>
<Alert sx={styles.buildNotification} severity="warning">
<AlertTitle>Warning</AlertTitle>
Please wait for LED to resume blinking before
disconnecting power
</Alert>
</>
)}
<ShowAfterTimeout
timeout={
response?.buildFlashFirmware?.success &&
currentJobType === BuildJobType.BuildAndFlash &&
deviceTarget?.flashingMethod === FlashingMethod.WIFI
? 15000
: 1000
}
active={!buildInProgress}
>
<Box sx={styles.buildNotification}>
<BuildResponse response={response?.buildFlashFirmware} />
</Box>
{response?.buildFlashFirmware?.success && hasLuaScript && (
<>
<Alert sx={styles.buildNotification} severity="info">
<AlertTitle>Update Lua Script</AlertTitle>
Make sure to update the Lua script on your radio
</Alert>
</>
)}
</ShowAfterTimeout>
{response?.buildFlashFirmware?.success &&
currentJobType === BuildJobType.Build && (
<>
Expand All @@ -1038,14 +1069,6 @@ const ConfiguratorView: FunctionComponent<ConfiguratorViewProps> = (props) => {
</Alert>
</>
)}
{response?.buildFlashFirmware?.success && hasLuaScript && (
<>
<Alert sx={styles.buildNotification} severity="info">
<AlertTitle>Update Lua Script</AlertTitle>
Make sure to update the Lua script on your radio
</Alert>
</>
)}
</CardContent>
<Divider />
</>
Expand Down

0 comments on commit 68de70e

Please sign in to comment.