8000 Apple pickers: thicket-pickers-apple over PHPicker, UIDocumentPicker, NSOpenPanel/NSSavePanel (#125) by rleibman · Pull Request #142 · rleibman/thicket · GitHub
[go: up one dir, main page]

Skip to content

Apple pickers: thicket-pickers-apple over PHPicker, UIDocumentPicker, NSOpenPanel/NSSavePanel (#125) - #142

Merged
rleibman merged 13 commits into
mainfrom
issue/125-apple-pickers
Nov 3, 2026
Merged

rleibman merged 13 commits into
mainfrom
issue/125-apple-pickers

Conversation

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

Closes #125.

What

thicket-pickers-apple: the Apple half of thicket-pickers, a Swift library of its own (libthicketpickers.a), in platforms. Both Apple galleries pass pickers = Some((photos, documents)).

  • iOS: PHPickerViewController (images, selectionLimit = limit), UIDocumentPickerViewController(forOpeningContentTypes:asCopy: true), and forExporting:asCopy: true for save.
  • macOS: NSOpenPanel / NSSavePanel as sheets on the gallery's window.
  • Every pick is copied through PickedFiles on a worker thread. Results arrive on the main thread. A cancel answers empty, or None for save. Only one picker can be up at a time.
  • Swift, not a C helper: the pickers answer through delegate objects and completion blocks. C can't write those without an Objective-C file, and Scala Native compiles .c but not .m.
  • ABI: PickersAbi in tools/shim-gen (11 thk_pick_* functions, one callback type), checked by PickersConsistencySpec (shimGen 37 → 44).
  • A picked file is a hold. PHPicker deletes its temporary file when the loading callback returns, so that callback waits until Scala has copied the file and released the hold. The copy is made inside the callback, and no non-Scala thread enters Scala.
  • sbt-thicket gains thicketPickersApple and ThicketNativeFlags.applePickers. bin/verify-apple.sh gains a shim-pickers step.

Measured

macOS gallery 209 ok, 0 FAIL (196 + 13), screen unlocked
iOS gallery, "iPhone 17e" 218 ok, 0 FAIL (207 + 11). The photo is copied into the cache 7.3 s after the tap (the tapper's run included); the saved file is read back from Files' "On My iPhone" (31 bytes, the gallery's text)
shimGen/testFull 44/44
bin/verify-apple.sh "iPhone 17e" on f861be4 17/19 (see below)

Controls. With PickedFiles' copy removed (the original path handed back):

  • macOS: 2 FAIL (the photo and the document are not in the cache).
  • iOS: 2 FAIL (the photo comes from PhotosUI's temp directory; the document from the Inbox is already deleted, NoSuchFileException).
  • Restored, both pass.

verify-apple: two steps failed in the full run.

How it is driven

  • iOS: XCUITest reaches PhotosUI's grid and the document browser through the app's accessibility tree. The tapper gains photo, cancel, document and export. build-app.sh adds the logo with simctl addmedia, puts a text file in "On My iPhone", and checks the saved file afterwards.
  • macOS 27 (not exercised: the panel's OK button). The panels run in openAndSavePanelService even for an unsandboxed app:
    • -[NSSavePanel ok:] raises "not implemented", and neither key events nor (untrusted) accessibility reach the panel's buttons.
    • NSUseRemoteSavePanel=NO gives an in-process open panel, but only to a process with a bundle id; the save panel stays remote.
    • So the self-test checks the real sheet (types, multiple, suggested name) and the panel's own cancel(_:). It answers an accept with ApplePickers.testing.choose, which uses the panel's own completion with a known file.

Found on the way

  • On Xcode 27 a UI test that touched an app, SpringBoard included, took 300 s to tear down, which held up every later DRIVE line. The tapper now exit(0)s after tapping, and tap.sh reads its "tapped" line.
  • UIKit silently drops a picker presented while the last one is still animating away. The library now waits for the transition.

🤖 Generated with Claude Code

Roberto Leibman and others added 8 commits November 2, 2026 12:02
…), Swift library, ApplePickers

shimGen/testFull 44/44 (PickersConsistencySpec 7). libthicketpickers.a 68 128 bytes (macOS),
93 904 bytes (simulator).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
macOS gallery: 209 ok, 0 FAIL (196 + 13 picker checks); photo copied into the cache 282 ms
after the answer. macOS 27's panels are out of process (openAndSavePanelService): the sheet,
its configuration and its own cancel: are the real panel's; the accept is testing.choose.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… photo and document; verify-apple shim-pickers; sbt-thicket thicketPickersApple

XCUITest reaches PHPickerViewController's grid and the document browser through the app's
accessibility tree (measured on iPhone 17e with a probe app): photo, cancel, document and
export each tapped in ~5 s; a test that touched an app takes 300 s to tear down, so the
app actions exit(0) once tapped (18 s per tap.sh run instead of 314 s).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Control on macOS: with PickedFiles' copy removed (the original path handed back), the gallery
fails 2 checks (photo and document not in the cache); restored, 209 ok, 0 FAIL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…y once the last is dismissed

iOS gallery on iPhone 17e, before these: the deny tap's 300 s teardown held up every later
DRIVE line (11 FAIL); then the photo pick passed (copied 7 160 ms after the tap) but the
next picker, presented while the first was animating away, was dropped by UIKit (6 FAIL).

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

iOS gallery on iPhone 17e: ALL CHECKS PASSED, 218 ok (207 + 11 picker checks). The photo
copied into the cache 7 309 ms after the tap; the saved file read back from Files (31 bytes).

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

Controls, PickedFiles' copy removed: macOS 2 FAIL, iOS 2 FAIL (the photo handed back from
PhotosUI's temp directory; the document already deleted from the Inbox). Restored, both pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…S gallery 218 and todo 83 alone

ios-gallery failed on the known fresh-boot notifications trap (its 11 picker checks passed);
ios-todo (no pickers linked) failed 4 presentation checks. Both pass alone on the warm simulator.

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 reports two critical issues—an invalid JVM-to-Scala-Native sbt dependency and a likely non-compiling discard() implementation—plus a resource leak from an unclosed Files.list stream.

2 open issues
What changed in this PR

This pull request adds the Apple implementation of thicket-pickers by introducing a new Scala Native module (thicket-pickers-apple) backed by a Swift shim, and wires it into the iOS/macOS gallery examples, verification scripts, and shim-gen tooling.

Changes:

  • Add modules/pickers-apple (Scala Native + Swift) implementing photo/document pickers on iOS (PHPicker/UIDocumentPicker) and macOS (NSOpenPanel/NSSavePanel), copying picked files into the cache and returning results on the main thread.
  • Extend tools/shim-gen with a PickersAbi surface plus emit/parse/consistency tests for the new thk_pick_* ABI.
  • Update sbt tooling, examples, verification scripts, and documentation to support building/driving/testing Apple pickers.

Approval Readiness

This pull request requires changes.

File Notes
tools/​shim-gen/​src/​test/​scala/​thicket/​tools/​shim/​PickersConsistencySpec.scala Adds consistency tests to keep pickers header/externs/Swift shim aligned.
tools/​shim-gen/​src/​main/​scala/​thicket/​tools/​shim/​PickersAbi.scala Defines the thk_pick_* ABI surface for shim generation.
tools/​shim-gen/​src/​main/​scala/​thicket/​tools/​shim/​Parse.scala Updates parsing support for pickers callback typedef/typealias.
tools/​shim-gen/​src/​main/​scala/​thicket/​tools/​shim/​Main.scala Wires pickers header/extern outputs into shim-gen.
tools/​shim-gen/​src/​main/​scala/​thicket/​tools/​shim/​Emit.scala Emits pickers header and Scala externs.
tools/​sbt-thicket/​src/​test/​scala/​thicket/​sbt/​SharedFlagsSpec.scala Adds tests for new native flag/linking helpers.
tools/​sbt-thicket/​src/​main/​scala/​thicket/​sbt/​ThicketApplePlugins.scala Adds plugin support to unpack/use the pickers shim artifacts.
tools/​sbt-thicket/​shared/​src/​main/​scala/​thicket/​sbt/​ThicketNativeFlags.scala Adds Apple pickers native linking flags helper.
tools/​sbt-thicket/​README.md Documents new pickers-related sbt tasks/behavior.
modules/​pickers/​README.md Updates pickers documentation to include the Apple implementation.
modules/​pickers-apple/​src/​main/​scala/​thicket/​pickers/​apple/​PickersShim.scala Adds generated Scala Native extern bindings for the pickers ABI.
modules/​pickers-apple/​src/​main/​scala/​thicket/​pickers/​apple/​ApplePickers.scala Implements Apple pickers behavior (copy-to-cache, save staging, UI-thread delivery).
modules/​pickers-apple/​shim/​Sources/​PickersShim.swift Swift shim implementing thk_pick_* over iOS/macOS pickers and test hooks.
modules/​pickers-apple/​shim/​include/​thicket_pickers.h Generated C header describing the pickers ABI.
modules/​pickers-apple/​shim/​build-shim.sh Build script for libthicketpickers.a (macOS + iOS simulator).
modules/​pickers-apple/​.gitignore Ignores built shim outputs.
examples/​ios-host/​tapper/​TapperUITests/​TapperUITests.swift Extends UI tests to drive picker flows and adjusts teardown behavior.
examples/​ios-host/​tapper/​tap.sh Updates tapper driver script for new actions/log-based success detection.
examples/​gallery/​README.md Documents how Apple pickers are exercised/validated in the gallery.
examples/​gallery/​macos/​src/​main/​scala/​example/​gallery/​GalleryMac.scala Wires Apple pickers into the macOS gallery.
examples/​gallery/​ios/​src/​main/​scala/​example/​gallery/​GalleryIos.scala Wires Apple pickers into the iOS gallery.
examples/​gallery/​ios/​ios-app/​build-app.sh Adds simulator setup and verification steps for picker-driven flows.
examples/​gallery/​apple-shared/​src/​main/​scala/​example/​gallery/​GallerySelfTest.scala Integrates picker checks into the shared Apple gallery self-test.
examples/​gallery/​apple-shared/​src/​main/​scala/​example/​gallery/​GalleryPickerChecks.scala Implements self-test checks for picker behaviors and invariants.
docs/​decisions.md Records design/constraints/measurements for Apple pickers.
docs/​16-device-services.md Updates device-services documentation to reflect Apple pickers support.
docs/​14-releasing.md Updates release docs to include the new pickers-apple artifact.
docs/​12-component-status.md Updates component status/test counts for pickers and shim-gen.
build.sbt Adds the pickersApple module and wires it into builds/examples/tooling.
bin/​verify-apple.sh Adds a shim-pickers verification step and updates Apple verification flow.
.scalafmt.conf Excludes generated externs from scalafmt.

Review effort: Balanced

rleibman and others added 5 commits November 2, 2026 22:03
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Refactor staged file check to ensure resource closure.

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>
e67724d replaced `discard` but also removed `dir`, `file` and the
`onWorker(...) { written =>` that opens the block, so the file no longer
parsed (scalafmt: "`end of file` expected but `}` found" at line 100).
The three lines are back; the autofix's `discard` is kept.

Checked here: sbt scalafmtAll and platforms/Test/compile, 0 errors (it
failed before this change). Not checked: the Apple self-tests (they need
the Mac).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both PRs add a gallery section and a tapper action, so they meet in ten files:
- build.sbt, GalleryIos, GalleryMac: both shareApple and pickersApple, both
  services.
- GallerySelfTest: motion -> share -> clipboard -> pickers -> sheet. Share
  stays before the clipboard (its "Copy" must not be the last copy, #134).
- build-app.sh drive(): the four picker actions and share-copy.
- Tapper: both fixes for XCTest's 300 s tear-down kept. TapperUITests keeps
  #125's actions and exit(0), with #134's '<bundle id>|<label>' tap first
  (ending in done() too); tap.sh is #134's wait-and-kill loop, passing #125's
  TEST_RUNNER_APP and TEST_RUNNER_FILE, rebuilt when a .swift is newer.
- docs/12: both counts, noted as measured apart. docs/14: both modules.
  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
rleibman merged commit 6c2358a into main Nov 3, 2026
1 of 2 checks passed
rleibman added a commit that referenced this pull request Nov 3, 2026
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>
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. #142 is Apple code, the Apple galleries and
tooling, 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 pickers: PHPickerViewController, UIDocumentPickerViewController, NSOpenPanel / NSSavePanel

2 participants

0