From 53d19546e8be238074a141113002d89ce8b87aa0 Mon Sep 17 00:00:00 2001 From: Shane Sewell <2242776+ssewell@users.noreply.github.com> Date: Mon, 11 Sep 2023 10:57:11 -0500 Subject: [PATCH] Validate ID response from 3D printer and track by mainboard ID. Fixes #5. Fixes #6. --- src/renderer/App.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx index d6f9ea6..235c61f 100644 --- a/src/renderer/App.tsx +++ b/src/renderer/App.tsx @@ -4,6 +4,8 @@ import '../components/ProgressBar.css'; import Printer from 'components/Printer'; import { PrinterItem } from 'types/PrinterTypes'; +const RESPONSE_ID = 'f25273b12b094c5a8b9513a30ca60049'; // Id included in valid JSON response from 3D printer + export default function App() { const [data, setData] = useState>({}); const [debugMode, setDebugMode] = useState(false); @@ -11,9 +13,12 @@ export default function App() { useEffect(() => { return window.electron.ipcRenderer.on('update-printers', (udpData: any) => { const udpDataJson: PrinterItem = JSON.parse(udpData); + + if (udpDataJson.Id !== RESPONSE_ID) return; + setData((prevData) => ({ ...prevData, - [udpDataJson.Id]: udpDataJson, + [udpDataJson.Data.Attributes.MainboardID]: udpDataJson, })); }); }, []);