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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ project.excludeFilters = [
"modules/http-apple/src/main/scala/thicket/http/apple/HttpShim.scala"
"modules/device-apple/src/main/scala/thicket/device/apple/DeviceShim.scala"
"modules/motion-ios/src/main/scala/thicket/motion/ios/MotionShim.scala"
"modules/pickers-apple/src/main/scala/thicket/pickers/apple/PickersShim.scala"
]

maxColumn = 120
Expand Down
5 changes: 4 additions & 1 deletion bin/verify-apple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# shim-ios compile Shim+UIKit.swift (build-shim.sh ios-sim)
# shim-device compile thicket-device-apple's Swift library, macOS and simulator (#114)
# shim-motion compile thicket-motion-ios's Swift library, simulator only (#120)
# shim-pickers compile thicket-pickers-apple's Swift library, macOS and simulator (#125)
# abi shim-gen's consistency checks: ABI, C header, Scala externs, both shims
# secrets thicket-secrets-apple's tests against the real Keychain (#108): conformance, isolation
# link sbt nativeLink for the six Apple apps, after deleting their old outputs
Expand All @@ -27,7 +28,8 @@
# macos-lazy THICKET_LAZYTEST=1 todo-macos: 10 000 rows, virtualised and freed
# ios-gallery the gallery on the simulator (examples/gallery/ios/ios-app/build-app.sh): it
# opens Settings over the gallery and answers its notifications alert through an
# XCUITest (examples/ios-host/tapper); then simctl pbpaste must read its last copy
# XCUITest (examples/ios-host/tapper), which also answers its photo picker, document
# picker and save dialog (#125); then simctl pbpaste must read its last copy
# ios-todo the todo app on the simulator (examples/todo-apple/ios/ios-app/build-app.sh)
# ios-lazy the 10 000-row probe on the simulator
# fit ContentFit measured on both toolkits (shim/run-fit-harness.sh)
Expand Down Expand Up @@ -185,6 +187,7 @@ run shim-macos modules/renderer-apple/shim/build-shim.sh macos
run shim-ios modules/renderer-apple/shim/build-shim.sh ios-sim
run shim-device sh -c 'modules/device-apple/shim/build-shim.sh macos && modules/device-apple/shim/build-shim.sh ios-sim'
run shim-motion modules/motion-ios/shim/build-shim.sh ios-sim
run shim-pickers sh -c 'modules/pickers-apple/shim/build-shim.sh macos && modules/pickers-apple/shim/build-shim.sh ios-sim'
run abi sbt --error shimGen/testFull
run secrets sbt --error secretsApple/testFull
run link link_all
Expand Down
42 changes: 40 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,38 @@ lazy val pickersAndroid = project
.dependsOn(pickers.jvm, rendererAndroid)
.settings(commonSettings, name := "thicket-pickers-android", scalacOptions ++= Seq("-release", "17"))

/** The pickers on macOS and iOS (#125): `PHPickerViewController` and `UIDocumentPickerViewController` on iOS,
* `NSOpenPanel` and `NSSavePanel` sheets on macOS. A Swift library of its own (`shim/`, `libthicketpickers.a`) carried
* in the jar like `deviceApple`'s, so an app without it links none of it nor PhotosUI. `rendererApple` for `postToUi`,
* as `pickersGtk` uses its renderer's. In `platforms`; building the Swift needs Xcode, so only a Mac links it.
*/
lazy val pickersApple = project
.in(file("modules/pickers-apple"))
.enablePlugins(AutomateHeaderPlugin, com.github.sbt.git.GitVersioning, ScalaNativePlugin)
.dependsOn(pickers.native, rendererApple, core.native)
.settings(commonSettings, name := "thicket-pickers-apple")
// Generated by shimGen and compared byte for byte, like the renderer's `Shim.scala`.
.settings(headerSources / excludeFilter := HiddenFileFilter || "PickersShim.scala")
.settings(
publish / skip := !isMac,
Compile / packageBin / mappings ++= {
val shim = (ThisBuild / baseDirectory).value / "modules" / "pickers-apple" / "shim"
val conv = fileConverter.value
if !isMac then Seq.empty
else {
for target <- Seq("macos", "ios-sim") do {
val code = scala.sys.process.Process(Seq("bash", (shim / "build-shim.sh").getAbsolutePath, target), shim).!
if code != 0 then sys.error(s"pickers-apple build-shim.sh $target failed with exit $code")
}
Seq(
shim / "build" / "libthicketpickers.a" -> "thicket-pickers-apple/macos/libthicketpickers.a",
shim / "build-ios" / "libthicketpickers.a" -> "thicket-pickers-apple/ios-sim/libthicketpickers.a",
shim / "include" / "thicket_pickers.h" -> "thicket-pickers-apple/include/thicket_pickers.h"
).map((f, path) => conv.toVirtualFile(f.toPath) -> path)
}
}
)

/** Taking a photo with the platform's camera screen (`docs/16` §16.3, §16.10 item 5); the photo arrives as a copy in
* the app's cache, as a picked file does. GTK and macOS use `Camera.unavailable`.
*/
Expand Down Expand Up @@ -1007,6 +1039,7 @@ lazy val galleryAndroid = project
clipboardAndroid,
hapticsAndroid,
pickersAndroid,
pickersApple,
cameraAndroid,
shareAndroid,
httpChecks.jvm,
Expand All @@ -1029,7 +1062,7 @@ lazy val galleryMacos = project
.in(file("examples/gallery/macos"))
.enablePlugins(AutomateHeaderPlugin, com.github.sbt.git.GitVersioning, BuildInfoPlugin, ScalaNativePlugin)
.settings(thicketBuildInfo("example.gallery.macos.buildinfo"))
.dependsOn(rendererApple, galleryShared.native, storageApple, secretsApple, deviceApple, locationApple, clipboardApple, hapticsApple, shareApple)
.dependsOn(rendererApple, galleryShared.native, storageApple, secretsApple, deviceApple, locationApple, clipboardApple, hapticsApple, shareApple, pickersApple)
.settings(commonSettings)
.settings(appleNativeSettings)
.settings(galleryAppleSharedSources)
Expand All @@ -1038,6 +1071,10 @@ lazy val galleryMacos = project
.settings(
nativeConfig ~= thicket.sbt.ThicketNativeFlags.appleDevice(file("modules") / "device-apple" / "shim" / "build")
)
// thicket-pickers-apple's Swift library (#125): `modules/pickers-apple/shim/build-shim.sh` builds it.
.settings(
nativeConfig ~= thicket.sbt.ThicketNativeFlags.applePickers(file("modules") / "pickers-apple" / "shim" / "build")
)
.settings(
name := "gallery-macos",
publish / skip := true,
Expand All @@ -1048,7 +1085,7 @@ lazy val galleryIos = project
.in(file("examples/gallery/ios"))
.enablePlugins(AutomateHeaderPlugin, com.github.sbt.git.GitVersioning, BuildInfoPlugin, ScalaNativePlugin)
.settings(thicketBuildInfo("example.gallery.ios.buildinfo"))
.dependsOn(rendererApple, galleryShared.native, storageApple, secretsApple, deviceApple, locationApple, motionIos, clipboardApple, hapticsApple, shareApple)
.dependsOn(rendererApple, galleryShared.native, storageApple, secretsApple, deviceApple, locationApple, motionIos, clipboardApple, hapticsApple, shareApple, pickersApple)
.settings(commonSettings)
.settings(iosNativeSettings)
.settings(galleryAppleSharedSources)
Expand Down Expand Up @@ -1227,6 +1264,7 @@ lazy val platforms = project
hapticsAndroid,
pickersGtk,
pickersAndroid,
pickersApple,
cameraAndroid,
shareAndroid,
clipboardApple,
Expand Down
7 changes: 5 additions & 2 deletions docs/12-component-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ every remaining entry before it is built, not after.
| Motion | `modules/motion`, `motion-android` | done on Android (2026-10-30) — acceleration (gravity included), rotation rate and attitude through `SensorManager`, each a `Signal` at a requested `Rate`, running only while the app is in front; a sensor the device lacks is `Unavailable`. GTK uses `Motion.unavailable`. The gallery's Motion section is driven with `adb emu sensor set`. iOS (2026-10-31, #120): `thicket-motion-ios` over `CMMotionManager` (its own Swift library), acceleration converted from g and negated to Android's sign (unmeasured: no device); the simulator has no motion hardware, so the gallery checks each sensor's `Unavailable` reason and that nothing is started. macOS uses `Motion.unavailable`. `modules/motion/README.md` |
| Clipboard | `modules/clipboard`, `clipboard-gtk`, `clipboard-android`, `clipboard-apple` | done on GTK (`GdkClipboard`, read asynchronously) and Android (`ClipboardManager`) (2026-10-30), and on macOS and iOS (`NSPasteboard`, `UIPasteboard`, #123, 2026-10-30) — text only. The gallery copies and pastes twice, each paste showing that round's copy; on Apple `bin/verify-apple.sh` reads the last copy from outside the app. On iOS, reading text this process did not write shows "Allow Paste". `modules/clipboard/README.md` |
| Haptics | `modules/haptics`, `haptics-android`, `haptics-apple` | done on Android (2026-10-30) — `performHapticFeedback`, which `build.sh` finds in the system's vibrator history; GTK uses `Haptics.none`. Apple (#123, 2026-10-30): iOS's feedback generators and macOS's `NSHapticFeedbackManager` (a Force Touch trackpad); the self-test can only show the calls return — the simulator plays nothing. `modules/haptics/README.md` |
| Pickers | `modules/pickers`, `pickers-gtk`, `pickers-android` | done on GTK (`GtkFileDialog`) and Android (the photo picker, the Storage Access Framework) (2026-10-30) — `Photos.pick(limit)`, `Documents.open(types)` and `save(name, bytes)`; every picked file is copied into the app's cache and handed back as a `Path`, by callback. The gallery's self-tests answer the real pickers: `build.sh` taps Android's, the GTK test answers the in-process chooser. Apple is a Mac issue. `modules/pickers/README.md` |
| Pickers | `modules/pickers`, `pickers-gtk`, `pickers-android`, `pickers-apple` | done on GTK (`GtkFileDialog`) and Android (the photo picker, the Storage Access Framework) (2026-10-30) — `Photos.pick(limit)`, `Documents.open(types)` and `save(name, bytes)`; every picked file is copied into the app's cache and handed back as a `Path`, by callback. The gallery's self-tests answer the real pickers: `build.sh` taps Android's, the GTK test answers the in-process chooser. Apple (2026-11-02, #125): `thicket-pickers-apple`, its own Swift library — `PHPickerViewController` and `UIDocumentPickerViewController` on iOS, tapped in the iOS gallery by the XCUITest tapper; `NSOpenPanel` and `NSSavePanel` sheets on macOS, whose OK cannot be pressed from the app on macOS 27 (the panels are out of process), so the self-test answers an accept through the panel's own completion with a known file and cancels with the panel's own `cancel(_:)`. `modules/pickers/README.md` |
| Camera capture | `modules/camera`, `camera-android` | done on Android 10+ (2026-10-30) — `Camera.capturePhoto`: the camera app's screen, the photo copied into the app's cache as a JPEG, the MediaStore entry it was written to deleted; GTK uses `Camera.unavailable`. The gallery's self-test presses the emulator camera's shutter and Done, and backs out. Apple is a Mac issue. `modules/camera/README.md` |
| Share | `modules/share`, `share-android`, `share-apple` | done on Android (2026-11-01) — `Share.text` and `Share.file` through the chooser; a file is copied and served by Thicket's own `ThicketFileProvider`, read-only, with a grant for the chosen app; the app declares the provider in its manifest. GTK uses `Share.unavailable`. The gallery's self-test shares to its own share target, tapped in the real chooser. Done on macOS and iOS (#134) — `NSSharingServicePicker` and `UIActivityViewController`, a C helper, no Swift; the subject through a `UIActivityItemSource` made at run time; on iOS an XCUITest taps "Copy" in the sheet and `simctl pbpaste` reads the text; no macOS service is driven. `modules/share/README.md` |
| UI-thread seam | `UiThread`, `Host.install` | done — every host installs it since 2026-10-20; before that none did, so a ZIO effect's result was written from a worker thread. The default now throws |
Expand Down Expand Up @@ -367,7 +367,7 @@ someone who did not write the framework, running on all three targets.
| `hapticsJVM` / `hapticsNative` | 2 — `RecordingHaptics`, `Haptics.none` (2026-10-30) |
| `motionJVM` / `motionNative` | 5 — each reading follows its sensor, attitude as roll/pitch/yaw; stop in the background and with the owner; the rate asked for; a missing sensor; `Motion.unavailable` (2026-10-30) |
| `secretsApple` | 4 (2026-10-27, a Mac only: `bin/verify-apple.sh`'s `secrets` step) — an unsigned binary gets the login keychain; the 11 checks; services are separate; a status in Security's words |
| `shimGen` | 37 (the `thk_dev` ABI's 7 included, 2026-10-30; the `thk_mot` ABI's 7, 2026-10-31) |
| `shimGen` | 44 (the `thk_dev` ABI's 7 included, 2026-10-30; the `thk_mot` ABI's 7, 2026-10-31; the `thk_pick` ABI's 7, 2026-11-02) |
| `sbtThicket` | 9 |

Measured 2026-10-20 with `sbt --error testFull`, which `sbt checkLinux` and CI run; the
Expand All @@ -390,8 +390,11 @@ Clipboard and haptics section's 3 included. The two together are not measured ye
2026-11-01 (#118): iOS simulator **199** (191 + 8, the Location section, the listeners counted
through a wrapping provider and in `libthicketdevice.a`), macOS **192** with the screen locked
(191 + 1, location unavailable).
2026-11-02 (#125), on this branch's base: iOS simulator ("iPhone 17e") **218** (207 + 11, the
Pickers section, driven through the real pickers), macOS **209** (196 + 13), screen unlocked.
2026-11-02 (#134): macOS **208**, the Share section's 8 included (**204** with the screen locked,
in `bin/verify-apple.sh`); iOS simulator ("iPhone 18 Pro") **216**, its 9 included.
Each measured on its own branch; the gallery with both sections has not been run yet.

Four rules the migration established:

Expand Down
3 changes: 2 additions & 1 deletion docs/14-releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ The artefacts, with explicit suffixes, because sbt 2 has no `%%%`:
| `net.leibman:thicket-clipboard-gtk_native0.5_3` / `thicket-clipboard-android_3` | text on the system clipboard (`thicket-clipboard` comes with them) |
| `net.leibman:thicket-haptics_3` / `_native0.5_3`, `thicket-haptics-android_3` | haptic taps; on GTK, `Haptics.none` from `thicket-haptics` |
| `net.leibman:thicket-pickers-gtk_native0.5_3` / `thicket-pickers-android_3` | the photo picker, the document picker and save dialog (`thicket-pickers` comes with them) |
| `net.leibman:thicket-pickers-apple_native0.5_3` | the same on macOS and iOS: `PHPickerViewController` and `UIDocumentPickerViewController`, `NSOpenPanel` and `NSSavePanel` sheets, with its own Swift library inside the jar (`macos/` and `ios-sim/libthicketpickers.a`); the Apple renderer comes with it |
| `net.leibman:thicket-camera_3` / `_native0.5_3`, `thicket-camera-android_3` | taking a photo with the camera app; on GTK, `Camera.unavailable` from `thicket-camera` |
| `net.leibman:thicket-share_3` / `_native0.5_3`, `thicket-share-android_3` | the share sheet; on Android the app declares `ThicketFileProvider`; on GTK, `Share.unavailable` |
| `net.leibman:thicket-renderer-android_3` | the Android renderer (plain JVM bytecode, `-release 17`; R8 dexes it) |
Expand Down Expand Up @@ -178,5 +179,5 @@ renderers and the platform modules that are not in `root`: `thicket-http-apple`,
`thicket-secrets-apple`, `thicket-device-gtk`, `thicket-device-android`, `thicket-device-apple`,
`thicket-location-android`, `thicket-location-apple`, `thicket-motion-android`, `thicket-motion-ios`, `thicket-clipboard-gtk`,
`thicket-clipboard-android`, `thicket-clipboard-apple`, `thicket-haptics-android`,
`thicket-haptics-apple`, `thicket-pickers-gtk`, `thicket-pickers-android`,
`thicket-haptics-apple`, `thicket-pickers-gtk`, `thicket-pickers-android`, `thicket-pickers-apple`,
`thicket-camera-android`, `thicket-share-android` and `thicket-share-apple`.
8 changes: 7 additions & 1 deletion docs/16-device-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ this means many modules. Names follow the published ones:
| motion | `thicket-motion` (built) | `-android` (built), `-ios` (built, #120); GTK and macOS use `Motion.unavailable` |
| clipboard | `thicket-clipboard` (built) | `-gtk`, `-android`, `-apple` (built) |
| haptics | `thicket-haptics` (built) | `-android`, `-apple` (built); GTK uses `Haptics.none` |
| pickers: photos, documents | `thicket-pickers` (built; `Documents`, not `Files`) | `-gtk`, `-android` (built); `-apple` (Mac issue) |
| pickers: photos, documents | `thicket-pickers` (built; `Documents`, not `Files`) | `-gtk`, `-android` (built); `-apple` (built, #125) |
| camera capture | `thicket-camera` (built) | `-android` (built), `-apple` (Mac issue); GTK and macOS use `Camera.unavailable` |
| share | `thicket-share` (built) | `-android` (built; Thicket's own `ThicketFileProvider`, declared in the app's manifest), `-apple` (Mac issue); GTK uses `Share.unavailable` |

Expand Down Expand Up @@ -462,6 +462,12 @@ Every service gets a gallery section and self-test checks on every host where it
and `Documents.open`/`save`, driven in the real system UI. `build.sh` taps the Android
photo picker and documents UI; the GTK self-test answers the file chooser in-process
(`GDK_DEBUG=no-portals`).
- *Pickers on Apple, 2026-11-02 (#125):* `thicket-pickers-apple`, a Swift library of its
own: `PHPickerViewController` and `UIDocumentPickerViewController` on iOS, `NSOpenPanel` and
`NSSavePanel` sheets on macOS, each file copied through `PickedFiles`. The iOS gallery's
pickers are tapped by the XCUITest tapper. On macOS 27 the panels are out of process and
their OK cannot be pressed from the app, so the self-test answers an accept through the
panel's own completion with a known file; the sheet and its cancel are the real panel's.
- *Camera capture done on Android, `Unavailable` on GTK, 2026-10-30
(`modules/camera/README.md`):* the camera app writes to a MediaStore entry Thicket makes,
and the photo is copied into the cache and the entry deleted. Android 10+. `build.sh`
Expand Down
Loading
Loading
0