Skip to content

Commit 20975d3

Browse files
Satyam RajSatyam Raj
authored andcommitted
fix: retain camera preview window across camera toggles
1 parent 8c2608d commit 20975d3

4 files changed

Lines changed: 34 additions & 15 deletions

File tree

‎electron/cameraPreview.test.ts‎

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ describe("floating camera preview lifecycle", () => {
125125
.mockReturnValueOnce(overlay as unknown as BrowserWindow)
126126
.mockReturnValueOnce(replacement as unknown as BrowserWindow);
127127
preview.configure(sender, true, true);
128-
preview.configure(sender, false, false);
128+
preview.dispose();
129129
preview.configure(sender, true, true);
130130
replacement.emit("ready-to-show");
131131

@@ -146,14 +146,36 @@ describe("floating camera preview lifecycle", () => {
146146
expect(overlay.webContents.send).not.toHaveBeenCalled();
147147
});
148148

149-
it("releases listeners on camera-off rather than accumulating them between takes", () => {
150-
const { preview, sender, owner, overlay } = setup();
149+
it("creates a hidden exclusion window even when the camera starts off", () => {
150+
const { preview, sender, owner, overlay, create } = setup();
151+
preview.configure(sender, false, true);
152+
overlay.emit("ready-to-show");
153+
expect(create).toHaveBeenCalledOnce();
154+
expect(overlay.hide).toHaveBeenCalledOnce();
155+
expect(overlay.showInactive).not.toHaveBeenCalled();
156+
preview.frame(sender, jpeg);
157+
expect(overlay.webContents.send).not.toHaveBeenCalled();
158+
preview.configure(sender, true, true);
159+
expect(create).toHaveBeenCalledOnce();
160+
expect(overlay.showInactive).toHaveBeenCalledOnce();
161+
owner.emit("destroyed");
162+
expect(overlay.destroy).toHaveBeenCalledOnce();
163+
});
164+
165+
it("retains the exclusion window and one owner listener across camera toggles", () => {
166+
const { preview, sender, owner, overlay, create } = setup();
151167
for (let i = 0; i < 15; i++) {
152-
preview.configure(sender, true, false);
153-
overlay.emit("ready-to-show");
154-
preview.configure(sender, false, false);
168+
preview.configure(sender, true, true);
169+
if (i === 0) overlay.emit("ready-to-show");
170+
preview.configure(sender, false, true);
155171
}
172+
expect(create).toHaveBeenCalledOnce();
173+
expect(overlay.hide).toHaveBeenCalledTimes(15);
174+
expect(overlay.showInactive).toHaveBeenCalledTimes(15);
175+
expect(overlay.destroy).not.toHaveBeenCalled();
176+
expect(owner.listenerCount("destroyed")).toBe(1);
177+
owner.emit("destroyed");
156178
expect(owner.listenerCount("destroyed")).toBe(0);
157-
expect(overlay.destroy).toHaveBeenCalledTimes(15);
179+
expect(overlay.destroy).toHaveBeenCalledOnce();
158180
});
159181
});

‎electron/cameraPreview.ts‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ export class CameraPreviewController {
2626

2727
configure(owner: WebContents, enabled: boolean, visible: boolean): void {
2828
if (this.owner && this.owner !== owner) return;
29-
if (!enabled) {
30-
this.dispose();
31-
return;
32-
}
3329
if (!this.owner) {
3430
this.owner = owner;
3531
this.onOwnerDestroyed = () => {
@@ -53,9 +49,9 @@ export class CameraPreviewController {
5349
if (this.visible) this.window?.showInactive();
5450
});
5551
}
56-
this.visible = visible;
57-
if (visible && this.ready) this.window.showInactive();
58-
else if (!visible) this.window.hide();
52+
this.visible = enabled && visible;
53+
if (this.visible && this.ready) this.window.showInactive();
54+
else if (!this.visible) this.window.hide();
5955
}
6056

6157
hide(sender: WebContents): void {

‎electron/windows.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,6 @@ export function createCameraPreviewWindow(): BrowserWindow {
889889
resizable: false,
890890
maximizable: false,
891891
minimizable: false,
892-
closable: false,
893892
alwaysOnTop: true,
894893
skipTaskbar: true,
895894
show: false,

‎technical-documentation/testing/manual-e2e-checklist.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,3 +997,5 @@ These checks are the human slice: an agent cannot click Apple's picker (see abov
997997
| 2026-10-16 | dev `main` @ `b149c55` + #1278 macOS camera preview; Electron 41.2.1; capture helper built from the working tree with `swiftc` + macOS 26.5 SDK (SHA256 `06f142f075e4dd776b653f174379b2795a60d750557655f9bca6e2d2596c8f99`) | macOS 26.7, Apple Silicon, MacBook Pro Camera | **Partial — preview slice passed** | `mcp__cua_repl`: live circular self-view, show/hide during recording, three sizes and limit buttons, disabled preview button when camera is off, and recording finalization into screen MP4 + webcam WebM. Exercised OS dragging without independently measuring the final position. A take started with the preview hidden and showed it during capture; a decoded late screen frame contained no floating circle. Default placement and resize anchoring are covered by geometry tests. **Skipped:** Apple’s picker, fullscreen Spaces, other cameras, restart/cancel, export, exhaustive frame-by-frame exclusion, Windows/Linux and the remaining checklist. SwiftPM/XCTest unavailable locally; direct helper compilation passed. |
998998

999999
| 2026-10-19 | dev `codex/macos-floating-camera-preview`, rebased on `main` @ `3620cf8`, plus #1288 review changes; Electron 41.2.1; native helper rebuilt directly with `swiftc` + macOS 26.5 SDK | macOS 26.7, Apple M5 Pro, MacBook Pro Camera | **Partial — preview review slice passed** | Computer-use verified the complete rounded rectangular camera frame, aspect-preserving resize, camera-off hiding the HUD preview control, and show/hide during a finalized camera take. In the same take, after 5 s settling per condition, 30 s process-tree CPU deltas were **17.5% hidden / 22.3% shown** (100%=one core; includes Electron children and capture helper). Native `recording-stopped` reported **0 droppedVideoFrames over the entire take**, covering both intervals; this counts screen-writer backpressure/append failures, not upstream capture or webcam drops. Screen 1 at 3024×1964, saved webcam verified 1920×1080 (30 fps requested); mic/system audio off, system cursor. One sequential pair, no statistical claim. **Skipped:** Apple’s picker, fullscreen Spaces, other cameras/platforms, restart/cancel, export, exhaustive exclusion and remaining checklist. |
1000+
1001+
| 2026-10-19 | dev #1288 on `8c2608d9` + preview lifetime/quit fixes; Electron 41.2.1 | macOS 26.7, Apple Silicon, MacBook Pro Camera | **Partial — lifecycle slice passed** | Computer-use camera off/on removed/restored the HUD preview control. Normal Cmd+Q exited the OpenScreen Electron process with the preview enabled. Unit tests verify the same preview window survives initial camera-off and repeated toggles, with one owner-destruction listener and cleanup on HUD destruction. **Skipped:** recording, export, capture-exclusion measurements, other platforms and remaining checklist; no native capture changes in this slice. |

0 commit comments

Comments
 (0)