Skip to content

Commit 5c1e8db

Browse files
committed
fix(linux): keep a user Stop out of the "stopped unexpectedly" toast
When the helper exited with an error after the user pressed Stop, the salvaged take was marked interrupted and the editor opened with "The screen capture stopped unexpectedly". Only a helper that dies before a stop is requested now marks the take interrupted; a failed user Stop keeps its salvaged take without that warning, and a Stop with nothing usable fails with the helper's reason as before. Refs #1573 (cherry picked from commit 8074c03)
1 parent 59aaca3 commit 5c1e8db

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎electron/ipc/handlers.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,6 +3009,10 @@ export function registerIpcHandlers(
30093009
try {
30103010
result = await session.stop();
30113011
} catch (error) {
3012+
// A Stop the user asked for fails as before, with the helper's reason.
3013+
if (!session.interrupted) {
3014+
throw error;
3015+
}
30123016
// The raw reason is in the log; the user is told what happened to the take.
30133017
console.error("Failed to stop native Linux recording:", error);
30143018
return { success: false, error: mainT("dialogs", "recording.captureLost") };

‎electron/native-bridge/capture/linuxNativeCaptureSession.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,29 @@ describe("LinuxNativeCaptureSession", () => {
897897

898898
await expect(session.stop()).rejects.toThrow(/exited/);
899899
});
900+
901+
it("keeps the take but does not call it interrupted when it fails after the user's Stop", async () => {
902+
vi.mocked(salvageNativeMacCapture).mockResolvedValueOnce({
903+
ok: true,
904+
screenVideoPath: "/tmp/recording.mp4",
905+
videoSamples: 300,
906+
durationSec: 10,
907+
truncatedBytes: 0,
908+
});
909+
const session = await capturingSession();
910+
const onInterrupted = vi.fn();
911+
session.onInterrupted = onInterrupted;
912+
913+
const stopping = session.stop();
914+
await flushStdout();
915+
helper.emit("exit", 1, null);
916+
const result = await stopping;
917+
918+
expect(result.path).toBe("/tmp/recording.mp4");
919+
expect(result.interrupted).toBeUndefined();
920+
expect(session.interrupted).toBe(false);
921+
expect(onInterrupted).not.toHaveBeenCalled();
922+
});
900923
});
901924

902925
/**

‎electron/native-bridge/capture/linuxNativeCaptureSession.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export class LinuxNativeCaptureSession {
132132
private stopped: LinuxCaptureResult | null = null;
133133
/** Set by `stop()` and `discard()`: from then on an exit is expected. */
134134
private stopRequested = false;
135+
private diedMidTake = false;
135136
/**
136137
* Called when the helper exits mid-take without being asked to: it crashed, was
137138
* killed, or lost its stream. Without it the HUD kept counting and the user found
@@ -232,6 +233,7 @@ export class LinuxNativeCaptureSession {
232233
this.stoppedResolve = null;
233234
this.stoppedReject = null;
234235
if (this.capturing && !this.stopRequested) {
236+
this.diedMidTake = true;
235237
console.error(`[capture-linux] the helper died mid-take: ${reason}`);
236238
this.onInterrupted?.();
237239
}
@@ -521,11 +523,18 @@ export class LinuxNativeCaptureSession {
521523
),
522524
...(this.sourceKind ? { sourceKind: this.sourceKind } : {}),
523525
...(this.videoEncoder ? { videoEncoder: this.videoEncoder } : {}),
524-
interrupted: true,
526+
// A helper that fails while stopping on the user's Stop still keeps its take,
527+
// but the user stopped it: no "stopped unexpectedly" warning.
528+
...(this.diedMidTake ? { interrupted: true as const } : {}),
525529
};
526530
return this.stopped;
527531
}
528532

533+
/** The helper exited mid-take before anyone asked it to stop. */
534+
get interrupted() {
535+
return this.diedMidTake;
536+
}
537+
529538
/** Kills the helper and discards whatever it wrote. */
530539
discard() {
531540
this.stopRequested = true;

0 commit comments

Comments
 (0)