From 9447f1c8dd7f517bbd9496fa9e9a8262c147c547 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Kazuhiro Date: Mon, 19 Feb 2024 16:30:03 +0900 Subject: [PATCH] Devtools: show toggle recording button in TelemetryView --- .../src/components/TelemetryView.tsx | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/tmtc-c2a/devtools_frontend/src/components/TelemetryView.tsx b/tmtc-c2a/devtools_frontend/src/components/TelemetryView.tsx index 31754e22..a87f8af1 100644 --- a/tmtc-c2a/devtools_frontend/src/components/TelemetryView.tsx +++ b/tmtc-c2a/devtools_frontend/src/components/TelemetryView.tsx @@ -6,6 +6,7 @@ import { useClient } from "./Layout"; import { useParams } from "react-router-dom"; import { Helmet } from "react-helmet-async"; import { TelemetrySchema } from "../proto/tmtc_generic_c2a"; +import type { RecordingStatus } from "../worker"; const buildTelemetryFieldTreeBlueprintFromSchema = ( tlm: TelemetrySchema, @@ -162,6 +163,76 @@ const InlineNamespaceContentCell: React.FC = ({ }; export const TelemetryView: React.FC = () => { + const { client } = useClient(); + const [recorderStatus, setRecordingStatus] = useState( + null, + ); + const params = useParams(); + const tmivName = params["tmivName"]!; + useEffect(() => { + const readerP = client + .openRecordingStatusStream() + .then((stream) => stream.getReader()); + let cancel; + const cancelP = new Promise((resolve) => (cancel = resolve)); + Promise.all([readerP, cancelP]).then(([reader]) => reader.cancel()); + readerP.then(async (reader) => { + // eslint-disable-next-line no-constant-condition + while (true) { + const next = await reader.read(); + if (next.done) { + break; + } + setRecordingStatus(next.value); + } + }); + return cancel; + }, [client]); + + const toggleRecordingStatus = async () => { + if (!recorderStatus?.directoryIsSet) { + const directoryHandle = await window.showDirectoryPicker({ + mode: "readwrite", + }); + client.setRootRecordDirectory(directoryHandle); + } + if (recorderStatus?.recordingTelemetries.has(tmivName)) { + client.disableRecording(tmivName); + } else { + client.enableRecording(tmivName); + } + }; + + + + const recording = + recorderStatus?.recordingTelemetries?.has(tmivName) ?? false; + + const recordingMenuItemsWhenRecording = ( + <> +
  • Recording: ON
  • +
  • Stop Recording
  • + + ); + const recordingMenuItemsWhenNotRecording = ( + <> +
  • Recording: OFF
  • +
  • Start Recording
  • + + ); + return ( + <> + + + + ); +}; + +const TelemetryViewBody: React.FC = () => { const params = useParams(); const tmivName = params["tmivName"]!; const {