Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
feat: enhance restart recording functionality to prevent concurrent restarts
Prayas Lashkarie2147bec63cf
diff --git a/src/hooks/useScreenRecorder.ts b/src/hooks/useScreenRecorder.tsindex a69da598f..cce4df2a5 100644--- a/src/hooks/useScreenRecorder.ts+++ b/src/hooks/useScreenRecorder.ts@@ -63,6 +63,7 @@ export function useScreenRecorder(): UseScreenRecorderReturn {const chunks = useRef<Blob[]>([]);const startTime = useRef<number>(0);const discardRecording = useRef(false);+ const restarting = useRef(false);const selectMimeType = () => {const preferred = [@@ -378,22 +379,26 @@ export function useScreenRecorder(): UseScreenRecorderReturn {};const restartRecording = async () => {- if (!recording) return;+ if (restarting.current) return;++ const recorder = mediaRecorder.current;+ if (!recorder || recorder.state !== "recording") return;++ restarting.current = true;discardRecording.current = true;- // Wait for the old recorder's onstop to fully complete before starting- // a new session, so the discard logic doesn't race with new chunks.const waitForStop = new Promise<void>((resolve) => {- if (mediaRecorder.current) {- mediaRecorder.current.addEventListener("stop", () => resolve(), { once: true });- } else {- resolve();- }+ recorder.addEventListener("stop", () => resolve(), { once: true });});stopRecording.current();await waitForStop;- await startRecording();++ try {+ await startRecording();+ } finally {+ restarting.current = false;+ }};return {