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(recording): address CodeRabbit review on #527
Etienne Lescot114934e810f9
diff --git a/electron/native-bridge/cursor/recording/macNativeCursorAccess.test.ts b/electron/native-bridge/cursor/recording/macNativeCursorAccess.test.tsindex 51a3f2c1c..a8a7dfd8c 100644--- a/electron/native-bridge/cursor/recording/macNativeCursorAccess.test.ts+++ b/electron/native-bridge/cursor/recording/macNativeCursorAccess.test.ts@@ -15,21 +15,24 @@ vi.mock("node:child_process", async (importOriginal) => {return { ...actual, spawn, default: { ...((actual as WithDefault).default ?? {}), spawn } };});+const mocks = vi.hoisted(() => ({+ isTrustedAccessibilityClient: vi.fn(() => true),+ // Shared rather than two separate vi.fn()s so a test can make every candidate path+ // unreadable and reach the missing-helper branch.+ accessSync: vi.fn(),+}));+vi.mock("node:fs", async (importOriginal) => {const actual = await importOriginal<typeof import("node:fs")>();- // No helper binary exists in a test checkout; pretend the first candidate path- // is executable so path resolution is not what is under test.+ // No helper binary exists in a test checkout; by default pretend the first candidate+ // path is executable so path resolution is not what is under test.return {...actual,- accessSync: vi.fn(),- default: { ...((actual as WithDefault).default ?? {}), accessSync: vi.fn() },+ accessSync: mocks.accessSync,+ default: { ...((actual as WithDefault).default ?? {}), accessSync: mocks.accessSync },};});-const mocks = vi.hoisted(() => ({- isTrustedAccessibilityClient: vi.fn(() => true),-}));-vi.mock("electron", () => ({systemPreferences: { isTrustedAccessibilityClient: mocks.isTrustedAccessibilityClient },screen: {@@ -73,6 +76,7 @@ beforeEach(() => {spawnMock.mockReturnValue(helper as unknown as ReturnType<typeof spawn>);mocks.isTrustedAccessibilityClient.mockReset();mocks.isTrustedAccessibilityClient.mockReturnValue(true);+ mocks.accessSync.mockReset();const silence = () => {// The access probe logs every helper diagnostic; keep the test output readable.};@@ -155,6 +159,39 @@ describe("requestMacCursorAccessibilityAccess", () => {}});+ /**+ * The other half of #515's conflation, and the branch whose dialog used to tell the+ * user to run a build script. No helper on disk is not a permission problem either.+ */+ it("reports an absent helper as unavailable, not as a denial", async () => {+ mocks.accessSync.mockImplementation(() => {+ throw new Error("ENOENT");+ });+ mocks.isTrustedAccessibilityClient.mockReturnValue(false);++ const access = await requestMacCursorAccessibilityAccess();++ expect(access).toMatchObject({ success: true, granted: false, status: "missing-helper" });+ expect(access.accessibilityTrusted).toBe(false);+ expect(isMacCursorHelperUnavailable(access.status)).toBe(true);+ // Nothing was spawned: there was nothing to spawn.+ expect(spawnMock).not.toHaveBeenCalled();+ });++ /**+ * The probe must not raise the macOS Accessibility prompt. It runs before the helper+ * is even located, so on every unavailable branch it would be asking for a grant that+ * is not what is missing.+ */+ it("reads Accessibility trust without prompting", async () => {+ await settle(requestMacCursorAccessibilityAccess(), () =>+ helper.emitEvent({ type: "ready", timestampMs: 1, accessibilityTrusted: true }),+ );++ expect(mocks.isTrustedAccessibilityClient).toHaveBeenCalledWith(false);+ expect(mocks.isTrustedAccessibilityClient).not.toHaveBeenCalledWith(true);+ });+it("keeps the app's own trust separate from the helper's fate", async () => {mocks.isTrustedAccessibilityClient.mockReturnValue(false);diff --git a/electron/native-bridge/cursor/recording/macNativeCursorRecordingSession.ts b/electron/native-bridge/cursor/recording/macNativeCursorRecordingSession.tsindex 7baa33474..a8d916a59 100644--- a/electron/native-bridge/cursor/recording/macNativeCursorRecordingSession.ts+++ b/electron/native-bridge/cursor/recording/macNativeCursorRecordingSession.ts@@ -124,11 +124,22 @@ export async function requestMacCursorAccessibilityAccess(): Promise<MacCursorAc// The return value is the signal, not a side effect: it says whether OpenScreen.app// itself is trusted, independently of whether the child helper can be launched.+ //+ // `false`, so this is a silent read. Prompting here would ask for Accessibility+ // BEFORE discovering whether the helper can run at all — and in every branch below+ // where it cannot (missing-helper, error, exited, timeout) the grant is not what is+ // missing, so the prompt is exactly the noise this function now exists to stop.+ //+ // Nothing is lost on the one path that does ask the user for the grant: reaching+ // `not-determined` means the helper RAN, and it calls AXIsProcessTrustedWithOptions+ // with kAXTrustedCheckOptionPrompt itself on every start+ // (OpenScreenMacOSCursorHelper/main.swift), which is what puts OpenScreen in the+ // Accessibility list for the user to tick.let accessibilityTrusted = false;try {- accessibilityTrusted = systemPreferences.isTrustedAccessibilityClient(true);+ accessibilityTrusted = systemPreferences.isTrustedAccessibilityClient(false);} catch {- // Continue with helper probing; it can trigger the same macOS prompt.+ // Continue with helper probing; the helper performs the same check itself.}const helperPath = findMacCursorHelperPath();@@ -237,6 +248,10 @@ export class MacNativeCursorRecordingSession implements CursorRecordingSession {this.previousLeftButtonDown = false;this.consecutiveOutsideSamples = 0;+ // `true` here, unlike the silent read in requestMacCursorAccessibilityAccess: the+ // return value is discarded, so prompting IS the point. Recording is starting and+ // the helper is about to spawn, so this is the moment the grant can still change+ // what the take records.try {systemPreferences.isTrustedAccessibilityClient(true);} catch {diff --git a/scripts/check-macos-deployment-target.test.mjs b/scripts/check-macos-deployment-target.test.mjsindex 311e0c2d6..3bae0f29f 100644--- a/scripts/check-macos-deployment-target.test.mjs+++ b/scripts/check-macos-deployment-target.test.mjs@@ -34,12 +34,23 @@ const SUPPORTED_FLOOR = 12;* SwiftPM allows — `.macOS(.v12)` and `.macOS("12.3")`.*/function declaredMacOsFloor(source) {- const enumMatch = source.match(/\.macOS\(\s*\.v(\d+)(?:_\d+)?\s*\)/);+ // Scoped to the platforms block, with comments stripped from it, rather than matched+ // across the whole manifest. That block is preceded by a long comment discussing these+ // very version numbers, so a file-wide match is one careless edit away from reading the+ // prose instead of the declaration — and reporting a floor the build does not use is+ // the one failure this guard must not have.+ const block = source.match(/\bplatforms\s*:\s*\[([\s\S]*?)\]/)?.[1];+ if (!block) {+ return null;+ }+ const declarations = block.replace(/\/\/[^\n]*/g, "");++ const enumMatch = declarations.match(/\.macOS\(\s*\.v(\d+)(?:_\d+)?\s*\)/);if (enumMatch) {return Number(enumMatch[1]);}- const stringMatch = source.match(/\.macOS\(\s*"(\d+)(?:\.\d+)*"\s*\)/);+ const stringMatch = declarations.match(/\.macOS\(\s*"(\d+)(?:\.\d+)*"\s*\)/);return stringMatch ? Number(stringMatch[1]) : null;}@@ -67,4 +78,24 @@ describe("macOS native helper deployment target", () => {expect(declaredMacOsFloor('platforms: [ .macOS("12.3") ]')).toBe(12);expect(declaredMacOsFloor("platforms: [ .iOS(.v16) ]")).toBeNull();});++ it("reads the declaration, not prose that happens to mention a version", () => {+ // The real manifest carries exactly this shape: a comment about the floor sitting+ // directly above the floor. Matching file-wide would report 12 while the build used+ // 13 — a guard that passes for the very bug it exists to catch.+ const decoyAbove = [+ "// It was .macOS(.v12) until this changed; see issue #515.",+ "platforms: [",+ "\t.macOS(.v13)",+ "],",+ ].join("\n");+ expect(declaredMacOsFloor(decoyAbove)).toBe(13);++ const decoyInside = ["platforms: [", "\t// was .macOS(.v12)", "\t.macOS(.v13)", "],"].join(+ "\n",+ );+ expect(declaredMacOsFloor(decoyInside)).toBe(13);++ expect(declaredMacOsFloor("// .macOS(.v12) with no platforms block at all")).toBeNull();+ });});diff --git a/src/hooks/useScreenRecorder.ts b/src/hooks/useScreenRecorder.tsindex a1154c13b..939448185 100644--- a/src/hooks/useScreenRecorder.ts+++ b/src/hooks/useScreenRecorder.ts@@ -48,6 +48,31 @@ const RECORDING_FILE_PREFIX = "recording-";const VIDEO_FILE_EXTENSION = ".webm";const WEBCAM_FILE_SUFFIX = "-webcam";+/**+ * The cursor mode a BROWSER-pipeline take can actually honour, which is not always the+ * one the user picked.+ *+ * Only win32 reaches that pipeline through `getDisplayMedia`, the sole browser API here+ * that can exclude the system cursor (`cursor: "never"`). Everywhere else the+ * desktop-capture stream bakes the real cursor into the pixels, so keeping+ * "editable-overlay" would start cursor telemetry and have the editor composite a+ * SECOND, synthetic cursor on top of it.+ *+ * This only bites when a platform falls back to browser capture with the editable cursor+ * selected — on macOS 12 that is now the normal path (#515), and on Linux it is the+ * no-PipeWire path, where the same latent defect lives.+ *+ * One function rather than the expression inlined twice: the mode reported to the main+ * process at start and the mode persisted at finalize have to agree, and they are ~1200+ * lines apart.+ */+function effectiveBrowserCursorMode(+ platform: string,+ requested: CursorCaptureMode,+): CursorCaptureMode {+ return platform === "win32" ? requested : "system";+}+const AUDIO_BITRATE_VOICE = 128_000;const AUDIO_BITRATE_SYSTEM = 192_000;@@ -550,7 +575,16 @@ export function useScreenRecorder(): UseScreenRecorderReturn {? { videoData: webcamVideoData, fileName: webcamFileName }: undefined,createdAt: activeRecordingId,- cursorCaptureMode,+ // What this take actually did, not what was requested. Only the browser+ // pipeline reaches this finalizer (stopRecording returns earlier for all+ // three native paths), and off win32 it cannot exclude the system cursor+ // — so the mode reported to the main process was forced to "system" and+ // the stored metadata has to agree. It is user-visible: `openscreen+ // project show` prints it.+ cursorCaptureMode: effectiveBrowserCursorMode(+ window.electronAPI.getPlatform(),+ cursorCaptureMode,+ ),durationMs: duration,});@@ -1676,19 +1710,7 @@ export function useScreenRecorder(): UseScreenRecorderReturn {preparedRecordingId?: number | null,) => {const platform = window.electronAPI.getPlatform();-- // Only the win32 branch below reaches the browser pipeline through- // getDisplayMedia, which is the sole browser API here that can exclude the- // system cursor (`cursor: "never"`). Everywhere else the desktop-capture- // stream bakes the real cursor into the pixels, so reporting- // "editable-overlay" to the main process would start cursor telemetry and- // have the editor composite a SECOND, synthetic cursor on top of it.- //- // This only bites when a platform falls back to browser capture with the- // editable cursor selected — on macOS 12 that is now the normal path (#515),- // and on Linux it is the no-PipeWire path, where the same latent defect lives.- const browserCursorCaptureMode: CursorCaptureMode =- platform === "win32" ? cursorCaptureMode : "system";+ const browserCursorCaptureMode = effectiveBrowserCursorMode(platform, cursorCaptureMode);try {if (!isCountdownRunActive(countdownRunToken)) {