Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(record): let a second click during the microphone check take the first back

EtienneLescot8650f9d9f843
diff --git a/src/components/ai-edition/v4/RecStage.test.tsx b/src/components/ai-edition/v4/RecStage.test.tsx
index 8e6264c7c..ca3d7c3e7 100644
--- a/src/components/ai-edition/v4/RecStage.test.tsx
+++ b/src/components/ai-edition/v4/RecStage.test.tsx
@@ -305,6 +305,20 @@ describe("RecStage controls", () => {
expect(toast.error).not.toHaveBeenCalled();
});
+ it("lets a second click during the microphone check take the first one back", async () => {
+ const { getRecordingPrefs, setRecordingPrefs } = stubRecordingPrefs({ micEnabled: false });
+ stubMediaDevices([{ kind: "audioinput", deviceId: "mic-1" }]);
+ renderRecStage();
+ await waitFor(() => expect(getRecordingPrefs).toHaveBeenCalled());
+
+ fireEvent.click(pill("rec.microphone"));
+ fireEvent.click(pill("rec.microphone"));
+
+ await new Promise((resolve) => setTimeout(resolve, 0));
+ expect(pill("rec.microphone")).toHaveAttribute("aria-pressed", "false");
+ expect(setRecordingPrefs).not.toHaveBeenCalledWith({ micEnabled: true });
+ });
+
it("runs one camera check for a double click", async () => {
const { getRecordingPrefs } = stubRecordingPrefs({ camEnabled: false });
stubCameras([]);
diff --git a/src/components/ai-edition/v4/RecStage.tsx b/src/components/ai-edition/v4/RecStage.tsx
index dd2f3bb32..c34ac79b2 100644
--- a/src/components/ai-edition/v4/RecStage.tsx
+++ b/src/components/ai-edition/v4/RecStage.tsx
@@ -151,16 +151,26 @@ export function RecStage({
};
// The same check as the HUD toggle: no input listed, never stored as on (#995).
+ // A second click while the check runs takes the first one back: the last click wins.
+ const micTurningOn = useRef(false);
const toggleMicrophone = () => {
if (prefs.micEnabled) {
updatePrefs({ micEnabled: false });
return;
}
+ if (micTurningOn.current) {
+ micTurningOn.current = false;
+ return;
+ }
+ micTurningOn.current = true;
void canTurnMicrophoneOn(t)
.then((ok) => {
- if (ok) updatePrefs({ micEnabled: true });
+ const wanted = micTurningOn.current;
+ micTurningOn.current = false;
+ if (ok && wanted) updatePrefs({ micEnabled: true });
})
.catch((err) => {
+ micTurningOn.current = false;
console.warn("[rec-stage] microphone check failed:", err);
});
};
diff --git a/src/components/launch/LaunchWindow.tsx b/src/components/launch/LaunchWindow.tsx
index 3728a9b58..b803eba0d 100644
--- a/src/components/launch/LaunchWindow.tsx
+++ b/src/components/launch/LaunchWindow.tsx
@@ -894,7 +894,9 @@ export function LaunchWindow() {
persistRecordingPrefs({ cursorCaptureMode: next });
}, [controlsLocked, cursorCaptureMode, persistRecordingPrefs, setCursorCaptureMode]);
- // Refuses a microphone the OS does not list, as the camera toggle does (#995).
+ // Refuses a microphone the OS does not list, as the camera toggle does (#995). A second
+ // click while the check runs takes the first one back: the last click wins.
+ const micTurningOn = useRef(false);
const toggleMicrophone = useCallback(() => {
if (controlsLocked) return;
if (microphoneEnabled) {
@@ -902,8 +904,15 @@ export function LaunchWindow() {
persistRecordingPrefs({ micEnabled: false });
return;
}
+ if (micTurningOn.current) {
+ micTurningOn.current = false;
+ return;
+ }
+ micTurningOn.current = true;
void canTurnMicrophoneOn(tEditor).then((ok) => {
- if (!ok) return;
+ const wanted = micTurningOn.current;
+ micTurningOn.current = false;
+ if (!ok || !wanted) return;
setMicrophoneEnabled(true);
persistRecordingPrefs({ micEnabled: true });
});