From 34d2e1e2e826ea7723409a290100f49221f7e800 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 2 Jan 2026 17:57:34 +0100 Subject: [PATCH] fix: wait for camera exposure to settle --- CHANGELOG.md | 1 + .../macos/Sources/Clawdis/CameraCaptureService.swift | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1185280cb..21151cea5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,7 @@ - macOS codesign: include camera entitlement so permission prompts work in the menu bar app. - Agent tools: map `camera.snap` JPEG payloads to `image/jpeg` to avoid MIME mismatch errors. - Tests: cover `camera.snap` MIME mapping to prevent image/png vs image/jpeg mismatches. +- macOS camera: wait for exposure/white balance to settle before capturing a snap to avoid dark images. - macOS packaging: move rpath config into swift build for reliability (#69) — thanks @petter-b - macOS: prioritize main bundle for device resources to prevent crash (#73) — thanks @petter-b - macOS remote: route settings through gateway config and avoid local config reads in remote mode. diff --git a/apps/macos/Sources/Clawdis/CameraCaptureService.swift b/apps/macos/Sources/Clawdis/CameraCaptureService.swift index 3c9d9c357..cf2d133d5 100644 --- a/apps/macos/Sources/Clawdis/CameraCaptureService.swift +++ b/apps/macos/Sources/Clawdis/CameraCaptureService.swift @@ -62,6 +62,7 @@ actor CameraCaptureService { session.startRunning() defer { session.stopRunning() } await Self.warmUpCaptureSession() + await self.waitForExposureAndWhiteBalance(device: device) let settings: AVCapturePhotoSettings = { if output.availablePhotoCodecTypes.contains(.jpeg) { @@ -257,6 +258,17 @@ actor CameraCaptureService { // A short delay after `startRunning()` significantly reduces "blank first frame" captures on some devices. try? await Task.sleep(nanoseconds: 150_000_000) // 150ms } + + private func waitForExposureAndWhiteBalance(device: AVCaptureDevice) async { + let stepNs: UInt64 = 50_000_000 + let maxSteps = 30 // ~1.5s + for _ in 0..