Stop macOS capture helper when parent closes its input

This commit is contained in:
webadderall
2026-09-23 14:56:55 +10:00
parent 7718ea8679
commit bde5a570bb
4 changed files with 13 additions and 1 deletions
@@ -1086,10 +1086,12 @@ DispatchQueue.global(qos: .utility).async {
}
if input == "stop" {
service.stop()
break
}
}
// EOF means the Electron parent exited or restarted. Finalize and release
// capture devices just as we do for an explicit stop command.
service.stop()
}
if !service.waitUntilFinished() {
@@ -8,6 +8,16 @@ const recorderSource = readFileSync(
);
describe("ScreenCaptureKitRecorder finalization coordination", () => {
it("finalizes on parent pipe closure as well as an explicit stop, exactly once", () => {
const commandLoop = recorderSource.slice(
recorderSource.indexOf("while let input = readLine"),
);
expect(commandLoop).toMatch(
/if input == "stop"\s*\{\s*break\s*\}\s*\}\s*\/\/.*?service\.stop\(\)/s,
);
expect(commandLoop.match(/service\.stop\(\)/g)).toHaveLength(1);
});
it("marks manual stops as participants in the shared finalization", () => {
expect(recorderSource).toContain("finalizeCapture(interactive: true)");
expect(recorderSource).toContain("finalization.outputResult.get()");