8000 Apple camera capture: thicket-camera-apple over UIImagePickerController (iOS); macOS Camera.unavailable (#129) by rleibman · Pull Request #143 · rleibman/thicket · GitHub
[go: up one dir, main page]

Skip to content
8000

Apple camera capture: thicket-camera-apple over UIImagePickerController (iOS); macOS Camera.unavailable (#129) - #143

Merged
rleibman merged 12 commits into
mainfrom
issue/129-apple-camera
Nov 3, 2026
Merged

rleibman merged 12 commits into
mainfrom
issue/129-apple-camera

Conversation

@rleibman
@rleibman rleibman commented Nov 3, 2026
Copy link
Copy Markdown
Owner

Closes #129.

What

  • thicket-camera-apple (iOS): AppleCamera(cache) presents UIImagePickerController with sourceType = .camera. The .originalImage is written as a JPEG (quality 0.9) to a temp file by the Swift library, copied into the cache through PickedFiles, and the temp file is deleted. Cancel answers None, and only one request runs at a time.
  • availability: if NSCameraUsageDescription is missing it throws IllegalStateException naming the key (through ApplePermissions). Otherwise it is Unavailable("This device has no camera") when isSourceTypeAvailable(.camera) is false, NeedsPermission(Camera) while the permission is not yet asked or is denied, and Unavailable when restricted.
  • Swift in the jar (libthicketcamera.a, 57 144 bytes, simulator only). UIImagePickerControllerDelegate is an Objective-C protocol, so it needs an Objective-C class. ABI: CameraAbi (thk_cam_*, 3 functions) with CameraConsistencySpec (7 tests). Also new: a shim-camera step in verify-apple.sh and thicketCameraApple in ThicketIosPlugin.
  • macOS: Camera.unavailable("no camera screen on the desktop"), matching GTK.
  • Gallery: the Pickers section shows the camera on its own when the host has no pickers yet (Apple, until Apple pickers: PHPickerViewController, UIDocumentPickerViewController, NSOpenPanel / NSSavePanel #125). The iOS build declares and grants the camera, so the Device section's camera check flipped to Granted on iOS. macOS still checks that it throws.

Finding: the simulator has a camera

On the iOS 27 simulator isSourceTypeAvailable(.camera) is true. The picker shows a grey simulated frame, but its shutter takes nothing: no review screen and no delegate call within 60 s (5 runs) or 300 s (2 runs). The iOS checks are therefore:

  • ready
  • the camera screen comes up
  • a second request answers None and the first stays up
  • the X answers None (6.3–9.7 s after the DRIVE line)
  • the shutter answers nothing and the screen stays up, then the X closes it

Not measured: a JPEG (FF D8 FF) coming back into the cache after a capture, with the temp file removed. The self-test checks for it, but only a device can run that path, and none was available. The no-camera path ("Take a photo" presents nothing) is also unmeasured.

Tapper fix (affects #114/#118 checks)

On Xcode 27, the XCUITest tapper's Tear Down took ~300 s after every tap (301.9 s, 304.0 s), with or without other simulators busy. That held back later DRIVE lines and failed the location checks in 3 of 3 runs. tap.sh now stops xcodebuild by PID once the test prints [tapper] done. After the change, "Don't Allow" was answered 6.3 s after its DRIVE line and the location checks passed. The tapper also accepts app <bundle id> <label>|?<label>.

Measured

  • bin/verify-apple.sh "iPhone Air": 19/19 steps on d1e524b.
  • iOS gallery 213; macOS gallery 197 twice, with the screen locked (+1: "the camera says the desktop has none to take a photo with").
  • shimGen 44; shimGen/run --check current.
  • Before the full pass, two fresh-boot iOS runs failed only on Apple device lifecycle and permissions: thicket-device-apple, the galleries' Device section #114's "notific 8000 ations start not yet asked" flake. One warm re-run was cut short because "iPhone Air" was shut down from outside this work. After simctl privacy reset all on the gallery, it passed.

Control

Not delivering a cancel's answer made "closing the camera screen with its X answers no photo" fail (None; presented false). The control the issue proposed (availability ignoring isSourceTypeAvailable) can't fail on a simulator that has a camera, so it was not run.

🤖 Generated with Claude Code

Roberto Leibman and others added 5 commits November 2, 2026 07:08
…camera checks

Not yet run on the simulator. shimGen: CameraConsistencySpec 7/7, generated files current;
libthicketcamera.a 57 144 bytes (simulator).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… XCUITest

Measured: isSourceTypeAvailable(.camera) is true on the iOS 27 simulator ('iPhone Air'),
and the picker shows a simulated grey frame. The tapper gains 'app <bundle> <labels>'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tapper stops at its answer

Camera-only run on 'iPhone Air' (iOS 27): 6 camera checks pass. The X answers no photo
6.5-9.3 s after the DRIVE line; the shutter took nothing in 60 s (no review screen). The
tapper's Tear Down took ~300 s on every tap (measured 301.9 and 304.0 s), so tap.sh now stops
xcodebuild by PID once the test prints '[tapper] done'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bin-free run of examples/gallery/ios/ios-app/build-app.sh: ALL CHECKS PASSED, 213 ok, after
simctl privacy reset of the gallery (the notifications flake). Control: a cancel not delivered
fails 'closing the camera screen with its X answers no photo'. WAIT_SECONDS 480.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bin/verify-apple.sh 'iPhone Air': 19/19 steps on d1e524b. iOS gallery 213, macOS gallery 197
twice (screen locked). shimGen 44 (CameraConsistencySpec 7). The iOS 27 simulator has a camera
screen whose shutter takes nothing (60 s, 5 runs): the capture path is unmeasured (no device).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

🟡 Changes recommended

Approval is blocked because the review evidence identifies critical unresolved issues: an incompatible Android→iOS Scala Native project dependency and outdated/misleading simulator camera availability documentation in both source and generated ABI docs.

2 open issues
What changed in this PR

This pull request adds Apple camera capture support by introducing a new iOS thicket-camera-apple implementation backed by UIImagePickerController via a packaged Swift static library and a small C ABI bridge, while explicitly keeping macOS camera behavior as unavailable. It also extends shim-gen tooling, Apple verification scripts, and gallery/self-test coverage to exercise the camera UI as far as the iOS simulator allows.

Changes:

  • Add modules/camera-apple (Scala Native + Swift shim + generated header/externs) and wire it into sbt and iOS gallery builds.
  • Extend tools/shim-gen with camera ABI definitions, emit/parsing support, and a consistency spec to keep Swift/C/Scala bindings aligned.
  • Update Apple gallery demos, self-tests, tapper tooling, verification scripts, and documentation/status tables to reflect iOS camera capability and macOS unavailability.
File Summary
tools/​shim-gen/​src/​test/​scala/​thicket/​tools/​shim/​CameraConsistencySpec.scala Adds camera ABI/header/externs/Swift consistency tests.
tools/​shim-gen/​src/​main/​scala/​thicket/​tools/​shim/​Parse.scala Extends shim parsing for camera callback types.
tools/​shim-gen/​src/​main/​scala/​thicket/​tools/​shim/​Main.scala Integrates camera header/extern generation into shim-gen outputs.
tools/​shim-gen/​src/​main/​scala/​thicket/​tools/​shim/​Emit.scala Emits generated camera C header and Scala externs.
tools/​shim-gen/​src/​main/​scala/​thicket/​tools/​shim/​CameraAbi.scala Defines the thk_cam_* ABI surface for camera capture.
tools/​sbt-thicket/​src/​main/​scala/​thicket/​sbt/​ThicketApplePlugins.scala Adds sbt tasks to unpack/link the camera shim for iOS.
tools/​sbt-thicket/​README.md Documents the new iOS camera shim unpack task.
README.md Updates repository/module documentation to include camera-apple.
modules/​camera/​README.md Documents Apple camera behavior, permissions, and cache-copy flow.
modules/​camera-apple/​src/​main/​scala/​thicket/​camera/​apple/​CameraShim.scala Generated Scala Native extern bindings for the camera shim.
modules/​camera-apple/​src/​main/​scala/​thicket/​camera/​apple/​AppleCamera.scala Implements iOS camera capture using the Swift shim and cache copying.
modules/​camera-apple/​shim/​Sources/​CameraShim.swift Swift implementation presenting UIImagePickerController and returning a temp JPEG path.
modules/​camera-apple/​shim/​include/​thicket_camera.h Generated C header for the camera shim ABI.
modules/​camera-apple/​shim/​build-shim.sh Script to build libthicketcamera.a for iOS simulator.
modules/​camera-apple/​.gitignore Ignores built shim outputs.
examples/​ios-host/​tapper/​TapperUITests/​TapperUITests.swift Extends tapper UI test helper to support in-app tapping by bundle id/labels.
examples/​ios-host/​tapper/​tap.sh Stops xcodebuild after tap completion; extends tap invocation syntax.
examples/​gallery/​shared/​shared/​src/​main/​scala/​example/​gallery/​PickersDemo.scala Adds a “NoPickers” path to allow camera-only UI where pickers aren’t available.
examples/​gallery/​shared/​shared/​src/​main/​scala/​example/​gallery/​Gallery.scala Updates gallery UI to show camera when pickers are absent.
examples/​gallery/​README.md Documents Apple camera checks and simulator limitations.
examples/​gallery/​macos/​src/​main/​scala/​example/​gallery/​GalleryMac.scala Sets macOS camera as Camera.unavailable(...).
examples/​gallery/​ios/​src/​main/​scala/​example/​gallery/​GalleryIos.scala Wires AppleCamera into iOS services and self-test hooks.
examples/​gallery/​ios/​ios-app/​build-app.sh Links the camera shim and configures iOS build/run for camera permission usage.
examples/​gallery/​apple-shared/​src/​main/​scala/​example/​gallery/​GallerySelfTest.scala Adds camera checks into the Apple self-test sequence.
examples/​gallery/​apple-shared/​src/​main/​scala/​example/​gallery/​GalleryDeviceChecks.scala Adjusts device permission expectations (iOS vs macOS) for camera.
examples/​gallery/​apple-shared/​src/​main/​scala/​example/​gallery/​GalleryCameraChecks.scala Adds camera-specific self-test logic including simulator behavior handling.
docs/​decisions.md Records decision log entry for Apple camera capture approach and findings.
docs/​16-device-services.md Updates device-services status/plans for iOS camera support.
docs/​14-releasing.md Adds thicket-camera-apple to release/publish documentation.
docs/​12-component-status.md Updates component status entry for Apple camera support.
build.sbt Adds the cameraApple project and wires it into the build graph.
bin/​verify-apple.sh Adds a shim-camera verification/build step.
.scalafmt.conf Excludes generated CameraShim.scala from formatting.

Review effort: Balanced

rleibman and others added 5 commits November 2, 2026 22:02
Clarified camera availability notes in documentation.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Conflict only in docs/decisions.md: both 2026-11-02 entries kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
a22fed9, edited outside sbt, left one Scaladoc line past the width; this
is sbt scalafmtAll's reflow and nothing else. platforms/Test/compile: 0
errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both add a gallery section and a tapper form:
- build.sbt, README, docs/14: cameraApple and shareApple both.
- GallerySelfTest: motion -> camera -> share -> clipboard -> sheet; share
  stays right before the clipboard (#134).
- build-app.sh drive(): photo and cancel (#129) and share-copy (#134).
- Tapper: three forms. "app <bundle id> a|b" (#129) is checked before
  '<bundle id>|<label>' (#134), since the first also has '|' in it. Every
  form now prints "[tapper] done" or "[tapper] failed" (#129's signal; #134's
  form gained both, its assertion now a guard). tap.sh is one wait-and-kill
  loop on those lines (both PRs had one, for the same 300 s tear-down),
  rebuilding when a .swift is newer than the build. "[tapper] tapped" no
  longer ends the wait: #129's form taps more than once.
- docs/12: Camera's row from #129, Share's from main; both counts, measured
  apart. decisions.md: both entries.

Checked here: sbt scalafmtAll and platforms/Test/compile, 0 errors; bash -n
on tap.sh and build-app.sh. Not checked: the Swift tapper compiling, and
any Apple self-test (they need the Mac); the combined gallery is unmeasured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rleibman and others added 2 commits November 3, 2026 09:44
Both add a Swift library through shim-gen and sbt-thicket, and a gallery
section driven by the tapper, so they meet in 17 files; everything is kept:
- shim-gen: Emit has pickers' and camera's header/extern emitters (main's
  file plus #143's two functions), Main generates all, Parse knows both
  callback types. sbt-thicket: ThicketPickersApple and ThicketCameraApple,
  both keys and settings. .scalafmt.conf excludes both generated externs.
- build.sbt, verify-apple.sh (shim-pickers and shim-camera), docs 12/14/16.
- Galleries: GallerySelfTest.run takes camera and pickers; the chain is
  motion -> camera -> share -> clipboard -> pickers -> sheet. GalleryIos
  builds both. build-app.sh links both libraries, has both DRIVE action sets
  (pick-photo/cancel-photo/... and photo/cancel), WAIT_SECONDS 600 (each
  alone fit in 480; together not measured).
- Tapper: main's actions (#125, #134) with #129's "app <id> a|b" form checked
  first; done() now prints "[tapper] done", which every form ends with, and
  tap.sh is #143's wait-and-kill loop on done/failed, passing #125's
  TEST_RUNNER_APP and TEST_RUNNER_FILE.

Checked here: sbt scalafmtAll and platforms/Test/compile, 0 errors;
shimGen 51/51 (with the next commit), sbtThicket 13/13; bash -n on tap.sh and
build-app.sh. Not checked: the Swift (tapper, shims) compiling, and any
Apple self-test; the gallery with both sections is unmeasured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7ba279a changed thk_cam_available's doc in CameraAbi.scala but not the
header generated from it, so shimGen's "checked-in generated files are
exactly what Abi generates" failed (stale: thicket_camera.h). This is
`sbt shimGen/run`'s output and nothing else. shimGen 51/51 after (50/51
before).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rleibman
rleibman merged commit 12b4932 into main Nov 3, 2026
2 checks passed
rleibman added a commit that referenced this pull request Nov 3, 2026
Conflict only in docs/decisions.md: both 2026-11-02 entries kept, the
embedding point's on top; the 11-01 camera-preview entry appears once (#144).
#143 and #144 are Apple code and docs, so the GTK (144) and Android (95)
counts measured on this branch stand. Checked here: sbt scalafmtAll,
Test/compile and platforms/Test/compile, 0 errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rleibman added a commit that referenced this pull request Nov 4, 2026
…ple (#147)

#142 and #143 each added their Apple module (Scala Native) to the Android
gallery's dependsOn, beside the Android one; the Android gallery uses
neither, and build.sh packages its own jar list, which never had them.

Measured: galleryAndroid/compile and platforms/Test/compile, 0 errors;
SELFTEST=1 examples/gallery/android/build.sh on s2test, 95 checks, ALL
CHECKS PASSED (95 before as well).

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Apple camera capture: thicket-camera-apple over UIImagePickerController (iOS); macOS Camera.unavailable

2 participants

0