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(mcp): route every take start and stop through one recording-state setter

EtienneLescotc541fffaa0cd
diff --git a/electron/ipc/handlers.ts b/electron/ipc/handlers.ts
index 8a3fa45d3..70d94c36c 100644
--- a/electron/ipc/handlers.ts
+++ b/electron/ipc/handlers.ts
@@ -1987,8 +1987,19 @@ export function registerIpcHandlers(
/** The editor holds changes it has not saved (main.ts): an MCP take would close it. */
editorHasUnsavedChanges?: () => boolean,
) {
- /** The HUD is recording a take, the user's or an MCP client's (`set-recording-state`). */
+ /** The HUD is recording a take, the user's or an MCP client's. Set by `setAppRecording` only. */
let appRecording = false;
+ /**
+ * Every start and stop of a take goes through here: the browser path's `set-recording-state`
+ * and the native paths, which start and stop in this process. The MCP recorder waits on it
+ * for a client's take to start, and the tray shows it. A native path that called
+ * `onRecordingStateChange` itself left the MCP recorder waiting on a take already running.
+ */
+ const setAppRecording = (recording: boolean, sourceName: string) => {
+ appRecording = recording;
+ mcpAppRecorder.recordingChanged(recording);
+ onRecordingStateChange?.(recording, sourceName);
+ };
const appSettings = new AppSettingsStore(app.getPath("userData"));
const broadcastSelectedSource = (source: SelectedSource | null) => {
for (const window of BrowserWindow.getAllWindows()) {
@@ -2756,9 +2767,7 @@ export function registerIpcHandlers(
// "Screen" }`, so the tray confidently displayed the name of a
// window the capture had never been told about.
linuxNativeCaptureSourceLabel = linuxSourceLabel(session.grantedSourceKind);
- if (onRecordingStateChange) {
- onRecordingStateChange(true, linuxNativeCaptureSourceLabel);
- }
+ setAppRecording(true, linuxNativeCaptureSourceLabel);
return { success: true, recordingId, path: outputPath };
} catch (error) {
@@ -2864,9 +2873,7 @@ export function registerIpcHandlers(
linuxNativeCaptureCursorMode = "editable-overlay";
const stoppedLabel = linuxNativeCaptureSourceLabel ?? linuxSourceLabel();
linuxNativeCaptureSourceLabel = null;
- if (onRecordingStateChange) {
- onRecordingStateChange(false, stoppedLabel);
- }
+ setAppRecording(false, stoppedLabel);
}
});
@@ -3056,9 +3063,7 @@ export function registerIpcHandlers(
});
const source = selectedSource || { name: "Screen" };
- if (onRecordingStateChange) {
- onRecordingStateChange(true, source.name);
- }
+ setAppRecording(true, source.name);
// Reported at start, not at stop: the helper decides the camera is a
// lost cause during its own init — before it announces "Recording
@@ -3320,9 +3325,7 @@ export function registerIpcHandlers(
: 0;
const source = selectedSource || { name: "Screen" };
- if (onRecordingStateChange) {
- onRecordingStateChange(true, source.name);
- }
+ setAppRecording(true, source.name);
return {
success: true,
@@ -3484,9 +3487,7 @@ export function registerIpcHandlers(
// leaving the handle set would make every later recording fail
// with "already running" against a process nobody can stop.
resetNativeWindowsCaptureState();
- if (onRecordingStateChange) {
- onRecordingStateChange(false, (selectedSource || { name: "Screen" }).name);
- }
+ setAppRecording(false, (selectedSource || { name: "Screen" }).name);
}
}
@@ -3646,9 +3647,7 @@ export function registerIpcHandlers(
} finally {
resetNativeWindowsCaptureState();
const source = selectedSource || { name: "Screen" };
- if (onRecordingStateChange) {
- onRecordingStateChange(false, source.name);
- }
+ setAppRecording(false, source.name);
}
});
@@ -3813,9 +3812,7 @@ export function registerIpcHandlers(
nativeMacIsPaused = false;
activeMacCaptureBounds = null;
const source = selectedSource || { name: "Screen" };
- if (onRecordingStateChange) {
- onRecordingStateChange(false, source.name);
- }
+ setAppRecording(false, source.name);
}
});
@@ -4132,11 +4129,7 @@ export function registerIpcHandlers(
}
const source = selectedSource || { name: "Screen" };
- appRecording = recording;
- mcpAppRecorder.recordingChanged(recording);
- if (onRecordingStateChange) {
- onRecordingStateChange(recording, source.name);
- }
+ setAppRecording(recording, source.name);
},
);
diff --git a/electron/ipc/recordingStateRouting.test.ts b/electron/ipc/recordingStateRouting.test.ts
new file mode 100644
index 000000000..13c7193f1
--- /dev/null
+++ b/electron/ipc/recordingStateRouting.test.ts
@@ -0,0 +1,51 @@
+// Every start and stop of a take reaches the MCP recorder.
+//
+// The native capture paths start and stop in the main process and used to call
+// `onRecordingStateChange` themselves, so only the browser path's `set-recording-state`
+// told the in-app MCP recorder a take had started. On Windows native capture, an MCP
+// `startRecording` then waited out its 120 s on a take already running.
+//
+// The fix routes every path through `setAppRecording` in handlers.ts. The scan below is
+// syntactic, like macSpaces.test.ts: registerIpcHandlers needs all of Electron to run.
+
+import fs from "node:fs";
+import path from "node:path";
+import { fileURLToPath } from "node:url";
+import { describe, expect, it } from "vitest";
+
+const source = fs.readFileSync(
+ path.join(path.dirname(fileURLToPath(import.meta.url)), "handlers.ts"),
+ "utf8",
+);
+
+/** The text of the `ipcMain.handle` registered for `channel`, up to the next one. */
+function handlerBody(channel: string): string {
+ const start = source.indexOf(`"${channel}"`);
+ expect(start, `no handler for ${channel}`).toBeGreaterThan(-1);
+ const end = source.indexOf("ipcMain.handle(", start);
+ return source.slice(start, end === -1 ? undefined : end);
+}
+
+const count = (pattern: RegExp) => source.match(pattern)?.length ?? 0;
+
+describe("recording state routing", () => {
+ it("changes the recording state in setAppRecording only", () => {
+ expect(count(/onRecordingStateChange(\?\.)?\(/g)).toBe(1);
+ expect(count(/mcpAppRecorder\.recordingChanged\(/g)).toBe(1);
+ expect(count(/(?<!let )\bappRecording = /g)).toBe(1);
+ const setter = source.slice(source.indexOf("const setAppRecording"));
+ const body = setter.slice(0, setter.indexOf("};"));
+ expect(body).toContain("appRecording = recording");
+ expect(body).toContain("mcpAppRecorder.recordingChanged(recording)");
+ expect(body).toContain("onRecordingStateChange?.(recording, sourceName)");
+ });
+
+ it.each(["windows", "mac", "linux"])("a native %s start and stop notify it", (platform) => {
+ expect(handlerBody(`start-native-${platform}-recording`)).toContain("setAppRecording(true");
+ expect(handlerBody(`stop-native-${platform}-recording`)).toContain("setAppRecording(false");
+ });
+
+ it("the browser path notifies it", () => {
+ expect(handlerBody("set-recording-state")).toContain("setAppRecording(recording");
+ });
+});