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(linux): attach the webcam with the cursor mode main stored

EtienneLescotb664d491caa6
diff --git a/src/hooks/useScreenRecorder.nativeLinuxWebcamCursor.test.tsx b/src/hooks/useScreenRecorder.nativeLinuxWebcamCursor.test.tsx
new file mode 100644
index 000000000..3bd1c2a04
--- /dev/null
+++ b/src/hooks/useScreenRecorder.nativeLinuxWebcamCursor.test.tsx
@@ -0,0 +1,127 @@
+// @vitest-environment jsdom
+import { act, renderHook } from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+
+vi.mock("@/contexts/I18nContext", () => ({
+ useScopedT: () => (key: string) => key,
+}));
+
+vi.mock("sonner", () => ({
+ toast: { error: vi.fn(), success: vi.fn(), info: vi.fn(), warning: vi.fn() },
+}));
+
+vi.mock("@/lib/requestCameraAccess", () => ({
+ requestCameraAccess: vi.fn(async () => ({ success: true, granted: true, status: "granted" })),
+}));
+
+// A webcam that "streamed to disk", so finalize hands back an asset without a real
+// MediaRecorder behind it.
+vi.mock("./recorderHandle", () => ({
+ createRecorderHandle: vi.fn(() => ({
+ recorder: { state: "inactive", stop: vi.fn() },
+ recordedBlobPromise: Promise.resolve(new Blob()),
+ isStreaming: () => true,
+ discard: vi.fn(async () => undefined),
+ })),
+}));
+
+import { useScreenRecorder } from "./useScreenRecorder";
+
+type ElectronAPI = Window["electronAPI"];
+
+let api: Record<string, ReturnType<typeof vi.fn>>;
+
+function stubElectronAPI() {
+ api = {
+ getRecordingPrefs: vi.fn(async () => ({
+ micEnabled: false,
+ micDeviceId: null,
+ micDeviceName: null,
+ camEnabled: true,
+ camDeviceId: null,
+ camDeviceName: null,
+ camQuality: "1080p",
+ systemAudioEnabled: false,
+ cursorCaptureMode: "system",
+ hideDesktopIcons: false,
+ autoZoomEnabled: true,
+ })),
+ setRecordingPrefs: vi.fn(async () => undefined),
+ onRecordingPrefsChanged: vi.fn(() => () => undefined),
+ getPlatform: vi.fn(() => "linux"),
+ getSelectedSource: vi.fn(async () => null),
+ isNativeLinuxCaptureAvailable: vi.fn(async () => ({ success: true, available: true })),
+ startNativeLinuxRecording: vi.fn(async () => ({ success: true, recordingId: 7 })),
+ stopNativeLinuxRecording: vi.fn(),
+ attachNativeLinuxWebcamRecording: vi.fn(async () => ({ success: true, session: {} })),
+ showCountdownOverlay: vi.fn(async () => true),
+ setCountdownOverlayValue: vi.fn(async () => true),
+ hideCountdownOverlay: vi.fn(async () => true),
+ setCurrentRecordingSession: vi.fn(async () => undefined),
+ setCurrentVideoPath: vi.fn(async () => undefined),
+ switchToEditor: vi.fn(async () => undefined),
+ };
+ window.electronAPI = api as unknown as ElectronAPI;
+ const track = { stop: vi.fn(), onended: null, getSettings: () => ({ width: 1280, height: 720 }) };
+ const stream = { getTracks: () => [track], getVideoTracks: () => [track] };
+ Object.defineProperty(navigator, "mediaDevices", {
+ configurable: true,
+ value: {
+ enumerateDevices: vi.fn(async () => [
+ { kind: "videoinput", deviceId: "cam-1", label: "Cam", groupId: "" },
+ ]),
+ getUserMedia: vi.fn(async () => stream),
+ addEventListener: vi.fn(),
+ removeEventListener: vi.fn(),
+ },
+ });
+ vi.stubGlobal("MediaRecorder", { isTypeSupported: () => true });
+}
+
+async function settle(ms = 0) {
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(ms);
+ });
+}
+
+beforeEach(() => {
+ vi.useFakeTimers();
+ stubElectronAPI();
+});
+
+afterEach(() => {
+ vi.useRealTimers();
+ vi.unstubAllGlobals();
+ vi.restoreAllMocks();
+});
+
+describe("useScreenRecorder native Linux webcam attachment", () => {
+ // "system" asked for; main stores what the portal granted. "editable-overlay" is the
+ // METADATA fallback of #1357, "system" a portal that did honour EMBEDDED.
+ it.each([
+ "editable-overlay",
+ "system",
+ ] as const)("attaches the webcam with the stored cursor mode %s", async (stored) => {
+ api.stopNativeLinuxRecording.mockResolvedValue({
+ success: true,
+ path: "/rec/a.mp4",
+ session: { screenVideoPath: "/rec/a.mp4", createdAt: 7, cursorCaptureMode: stored },
+ });
+ const view = renderHook(() => useScreenRecorder());
+ await settle();
+ await act(async () => {
+ view.result.current.toggleRecording();
+ });
+ await settle(3_500);
+ expect(view.result.current.recording).toBe(true);
+
+ await act(async () => {
+ view.result.current.toggleRecording();
+ });
+ await settle();
+
+ expect(api.attachNativeLinuxWebcamRecording).toHaveBeenCalledWith(
+ expect.objectContaining({ cursorCaptureMode: stored }),
+ );
+ });
+});
diff --git a/src/hooks/useScreenRecorder.ts b/src/hooks/useScreenRecorder.ts
index c5156749b..8c22aa9b7 100644
--- a/src/hooks/useScreenRecorder.ts
+++ b/src/hooks/useScreenRecorder.ts
@@ -959,7 +959,11 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
screenVideoPath: result.path,
recordingId: activeNativeRecording.recordingId,
webcam: webcamResult.asset,
- cursorCaptureMode,
+ // The mode main stored for the take, not the one asked for: a portal
+ // without EMBEDDED turns "system" into "editable-overlay" (#1357).
+ // This callback is also reached through the first render's
+ // stopRecording closure, so its own cursorCaptureMode is stale.
+ cursorCaptureMode: result.session?.cursorCaptureMode ?? cursorCaptureMode,
durationMs: webcamDurationMs,
...(typeof activeNativeRecording.webcamOffsetMs === "number"
? { webcamOffsetMs: activeNativeRecording.webcamOffsetMs }