diff --git a/electron/native-bridge/capture/linuxNativeCaptureSession.test.ts b/electron/native-bridge/capture/linuxNativeCaptureSession.test.ts index 52eb42e09..95cd4f127 100644 --- a/electron/native-bridge/capture/linuxNativeCaptureSession.test.ts +++ b/electron/native-bridge/capture/linuxNativeCaptureSession.test.ts @@ -700,6 +700,39 @@ describe("LinuxNativeCaptureSession", () => { expect(helper.stdinWrites).not.toContain("resume\n"); }); + it("closes the cursor pause range when the helper stops while paused, before stop() (#1637)", async () => { + const now = vi.spyOn(Date, "now").mockReturnValue(900); + const session = newSession(); + await startReady(session); + + emitCaptureStarted(1_000); + emitCursorSample(1_100); + await flushStdout(); + + now.mockReturnValue(1_200); + session.pause(); + emitCursorSample(1_300); + await flushStdout(); + + now.mockReturnValue(1_500); + helper.emitEvent({ + event: "capture-stopped", + timestampMs: 1_500, + path: "/tmp/recording.mp4", + durationMs: 200, + frames: 6, + dropped: 0, + }); + await flushStdout(); + + now.mockReturnValue(1_600); + const stopping = session.stop(); + helper.emit("exit", 0, null); + const result = await stopping; + + expect(result.cursor.samples.map((sample) => sample.timeMs)).toEqual([100]); + }); + /** * A non-fatal `error` event after the first frame does not end the capture; * a later wait is still satisfied. diff --git a/electron/native-bridge/capture/linuxNativeCaptureSession.ts b/electron/native-bridge/capture/linuxNativeCaptureSession.ts index fa4a3767d..d2512a87f 100644 --- a/electron/native-bridge/capture/linuxNativeCaptureSession.ts +++ b/electron/native-bridge/capture/linuxNativeCaptureSession.ts @@ -409,6 +409,16 @@ export class LinuxNativeCaptureSession { this.cursorPauseStartedAtMs = null; } + /** + * The cursor telemetry of a finished take, without its paused stretches. A take can + * end while paused, and the helper can end it before `stop()` runs: the open pause + * closes here, where every stopped snapshot is built. + */ + private stoppedCursorData(endMs?: number) { + this.completeCursorPauseRange(endMs); + return compactCursorTelemetryPauseRanges(this.cursor.toRecordingData(), this.cursorPauseRanges); + } + get isPaused() { return this.paused; } @@ -535,10 +545,7 @@ export class LinuxNativeCaptureSession { durationMs: Math.round(salvage.durationSec * 1000), frames: salvage.videoSamples, droppedFrames: 0, - cursor: compactCursorTelemetryPauseRanges( - this.cursor.toRecordingData(), - this.cursorPauseRanges, - ), + cursor: this.stoppedCursorData(), ...(this.sourceKind ? { sourceKind: this.sourceKind } : {}), ...(this.videoEncoder ? { videoEncoder: this.videoEncoder } : {}), ...(this.audioLost ? { audioLost: true as const } : {}), @@ -696,10 +703,7 @@ export class LinuxNativeCaptureSession { durationMs: payload.durationMs, frames: payload.frames, droppedFrames: payload.dropped, - cursor: compactCursorTelemetryPauseRanges( - this.cursor.toRecordingData(), - this.cursorPauseRanges, - ), + cursor: this.stoppedCursorData(payload.timestampMs), ...(this.sourceKind ? { sourceKind: this.sourceKind } : {}), ...(this.videoEncoder ? { videoEncoder: this.videoEncoder } : {}), ...(this.audioLost ? { audioLost: true as const } : {}),