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): run one camera check for a double click

EtienneLescotdbfec5ac444a
diff --git a/src/components/ai-edition/v4/RecStage.test.tsx b/src/components/ai-edition/v4/RecStage.test.tsx
index 99f7165d9..caee37c8e 100644
--- a/src/components/ai-edition/v4/RecStage.test.tsx
+++ b/src/components/ai-edition/v4/RecStage.test.tsx
@@ -265,6 +265,20 @@ describe("RecStage controls", () => {
expect(toast.error).not.toHaveBeenCalled();
});
+ it("runs one camera check for a double click", async () => {
+ const { getRecordingPrefs } = stubRecordingPrefs({ camEnabled: false });
+ stubCameras([]);
+ renderRecStage();
+ await waitFor(() => expect(getRecordingPrefs).toHaveBeenCalled());
+
+ fireEvent.click(pill("rec.camera"));
+ fireEvent.click(pill("rec.camera"));
+
+ await waitFor(() => expect(toast.error).toHaveBeenCalledWith("recording.cameraNotFound"));
+ expect(toast.error).toHaveBeenCalledTimes(1);
+ expect(window.electronAPI?.requestCameraAccess).toHaveBeenCalledTimes(1);
+ });
+
// A settings file written before the preference existed has no key, and every such
// installation has been getting auto-zoom — so absent must read as on, not off.
it("defaults on when a stored prefs blob has no autoZoomEnabled key", async () => {
diff --git a/src/components/ai-edition/v4/RecStage.tsx b/src/components/ai-edition/v4/RecStage.tsx
index debe493b1..5888be49f 100644
--- a/src/components/ai-edition/v4/RecStage.tsx
+++ b/src/components/ai-edition/v4/RecStage.tsx
@@ -140,9 +140,13 @@ export function RecStage({
updatePrefs({ camEnabled: false });
return;
}
- void canTurnCameraOn(t).then((ok) => {
- if (ok) updatePrefs({ camEnabled: true });
- });
+ void canTurnCameraOn(t)
+ .then((ok) => {
+ if (ok) updatePrefs({ camEnabled: true });
+ })
+ .catch((err) => {
+ console.warn("[rec-stage] camera check failed:", err);
+ });
};
const micDevices = useMicrophoneDevices(
diff --git a/src/lib/cameraAvailability.ts b/src/lib/cameraAvailability.ts
index 62d8c5110..075f62de7 100644
--- a/src/lib/cameraAvailability.ts
+++ b/src/lib/cameraAvailability.ts
@@ -16,15 +16,26 @@ async function hasCameraDevice(): Promise<boolean> {
}
}
+let pendingCheck: Promise<boolean> | null = null;
+
/**
* Whether the camera may be switched on, with a toast saying why not.
*
* The one check for every surface that turns the camera on (the HUD toggle, and the editor's
* Record mode), so neither stores `camEnabled: true` for a camera the other refuses (#998).
+ * A call made while one is pending, a double click, shares its answer: one access request,
+ * one toast.
*
* @param t The `editor` namespace translator.
*/
-export async function canTurnCameraOn(t: (key: string) => string): Promise<boolean> {
+export function canTurnCameraOn(t: (key: string) => string): Promise<boolean> {
+ pendingCheck ??= checkCameraCanTurnOn(t).finally(() => {
+ pendingCheck = null;
+ });
+ return pendingCheck;
+}
+
+async function checkCameraCanTurnOn(t: (key: string) => string): Promise<boolean> {
const accessResult = await requestCameraAccess();
if (!accessResult.success) {
toast.error(t("recording.failedCameraAccess"));