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
fix(hud): clear a stored camera when the toggle finds none
Etienne Lescotcb8bb1e27d52
diff --git a/src/hooks/useScreenRecorder.noCamera.test.tsx b/src/hooks/useScreenRecorder.noCamera.test.tsxindex bc0eba2bb..cd75f16b8 100644--- a/src/hooks/useScreenRecorder.noCamera.test.tsx+++ b/src/hooks/useScreenRecorder.noCamera.test.tsx@@ -84,6 +84,7 @@ describe("useScreenRecorder on a machine without a camera (#967)", () => {expect(view.result.current.webcamEnabled).toBe(false);expect(toast.error).toHaveBeenCalledWith("recording.cameraNotFound");expect(getUserMedia).not.toHaveBeenCalled();+ expect(setRecordingPrefs).toHaveBeenCalledWith({ camEnabled: false });});it("still turns a listed camera on", async () => {@@ -115,4 +116,26 @@ describe("useScreenRecorder on a machine without a camera (#967)", () => {expect(view.result.current.webcamEnabled).toBe(false);expect(toast.error).toHaveBeenCalledWith("recording.cameraNotFound");});++ // A saved camera name makes NotFoundError a "wait for the identity" case. In the+ // HUD, useCameraHudSync clears the identity once the list comes back empty, and+ // the acquire that follows takes the failure path.+ it("stores the camera as off once a restored camera identity is cleared", async () => {+ vi.spyOn(console, "warn").mockImplementation(() => undefined);+ stub({ ...prefs(true), camDeviceId: "cam-1", camDeviceName: "FaceTime HD Camera" });+ const view = renderHook(() => useScreenRecorder());+ await waitFor(() => expect(getUserMedia).toHaveBeenCalled());+ expect(view.result.current.webcamEnabled).toBe(true);+ expect(setRecordingPrefs).not.toHaveBeenCalled();++ act(() => {+ view.result.current.setWebcamDeviceId(undefined);+ view.result.current.setWebcamDeviceName(undefined);+ });++ await waitFor(() => {+ expect(setRecordingPrefs).toHaveBeenCalledWith({ camEnabled: false });+ });+ expect(view.result.current.webcamEnabled).toBe(false);+ });});diff --git a/src/hooks/useScreenRecorder.ts b/src/hooks/useScreenRecorder.tsindex f3c03bc9e..915fcf959 100644--- a/src/hooks/useScreenRecorder.ts+++ b/src/hooks/useScreenRecorder.ts@@ -504,6 +504,11 @@ export function useScreenRecorder(): UseScreenRecorderReturn {if (!(await hasCameraDevice())) {toast.error(t("recording.cameraNotFound"));+ // The toggle stores nothing on failure, so clear an "on" left behind by a+ // camera that was unplugged while it was in use.+ void window.electronAPI?.setRecordingPrefs?.({ camEnabled: false }).catch((error) => {+ console.warn("Failed to persist the camera preference:", error);+ });return false;}