8000 Apple share: thicket-share-apple, UIActivityViewController (iOS) and NSSharingServicePicker (macOS) (#134) by rleibman · Pull Request #141 · 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ modules/
haptics/ haptic taps; haptics-android/, haptics-apple/ (GTK: Haptics.none)
pickers/ photo and document pickers, save dialog; pickers-gtk/, pickers-android/
camera/ taking a photo with the camera app; camera-android/ (GTK: Camera.unavailable)
share/ the share sheet; share-android/ (GTK: Share.unavailable)
share/ the share sheet; share-android/, share-apple/ (GTK: Share.unavailable)
renderer-gtk/ GTK4 (Scala Native)
renderer-android/ android.view (Scala on ART)
renderer-apple/ AppKit + UIKit (Scala Native + Swift shim)
Expand Down
16 changes: 14 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,17 @@ lazy val clipboardApple = project
.dependsOn(clipboard.native, rendererApple)
.settings(commonSettings, name := "thicket-clipboard-apple")

/** Share on macOS and iOS (#134): `NSSharingServicePicker` and `UIActivityViewController`, through a C helper as
* `clipboardApple`'s (`resources/scala-native/thicket_share.c`); the text's subject goes through a
* `UIActivityItemSource` class the helper makes at run time, so there is no Swift. Files are shared as copies, through
* `thicket-share`'s `SharedFiles`. Needs no renderer. In `platforms`: linking needs Xcode.
*/
lazy val shareApple = project
.in(file("modules/share-apple"))
.enablePlugins(AutomateHeaderPlugin, com.github.sbt.git.GitVersioning, ScalaNativePlugin)
.dependsOn(share.native)
.settings(commonSettings, name := "thicket-share-apple")

/** Haptics on macOS and iOS (#123): `UIImpactFeedbackGenerator` and `UISelectionFeedbackGenerator`, and
* `NSHapticFeedbackManager` for a Force Touch trackpad, through a C helper as `clipboardApple`'s. Needs no renderer.
*/
Expand Down Expand Up @@ -1018,7 +1029,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)
.dependsOn(rendererApple, galleryShared.native, storageApple, secretsApple, deviceApple, locationApple, clipboardApple, hapticsApple, shareApple)
.settings(commonSettings)
.settings(appleNativeSettings)
.settings(galleryAppleSharedSources)
Expand All @@ -1037,7 +1048,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)
.dependsOn(rendererApple, galleryShared.native, storageApple, secretsApple, deviceApple, locationApple, motionIos, clipboardApple, hapticsApple, shareApple)
.settings(commonSettings)
.settings(iosNativeSettings)
.settings(galleryAppleSharedSources)
Expand Down Expand Up @@ -1220,6 +1231,7 @@ lazy val platforms = project
shareAndroid,
clipboardApple,
hapticsApple,
shareApple,
examplesShared.jvm,
examplesShared.native,
counterGtk,
Expand Down
4 changes: 3 additions & 1 deletion docs/12-component-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ every remaining entry before it is built, not after.
| 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` |
| 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` | 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. Apple is a Mac issue. `modules/share/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 |
| Apple ABI description + consistency check | `tools/shim-gen` | done — every `sui_*` function (110 externs in `Shim.scala`) and all 26 kind codes described; `thicket_apple.h` and `Shim.scala` are generated from it (adopted 2026-09-29, #3) and checked byte-for-byte; the two Swift shims' signatures and per-platform widget choice are checked against it, on any machine. Since #90 also `thicket-http-apple`'s 12 `thk_http_*` functions (`HttpAbi`): `thicket_http.h` and `HttpShim.scala` generated, `HttpShim.swift` checked |
| HTTP on Apple | `modules/http-apple` | done on iOS and macOS (#90) — `URLSessionBackend`, an sttp `SyncBackend` over `URLSession`, because the iOS SDK has no libcurl. Its own module and Swift library, not linked by an app that does not depend on it. The self-test checks against a local server pass on the iOS simulator and on macOS, among them one caliban-client query; each is seen to fail with its feature broken. Not a widget, so not in the gallery. The checks are now `examples/http`'s, shared by every platform; the Mac re-ran them there — 14/14 on macOS and the iOS simulator (2026-10-28, #112), with `bin/verify-apple.sh` running both so Apple CI does too |
Expand Down Expand U 8000 p @@ -390,6 +390,8 @@ 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 (#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.

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 @@ -70,6 +70,7 @@ The artefacts, with explicit suffixes, because sbt 2 has no `%%%`:
| `net.leibman:thicket-storage-apple_native0.5_3` | app directories and preferences on macOS and iOS (`thicket-storage` comes with it); no Swift |
| `net.leibman:thicket-secrets-apple_native0.5_3` | tokens and passwords in the Keychain on macOS and iOS (`thicket-secrets` comes with it); no Swift, and it links Security itself. An iOS app needs keychain entitlements, on the simulator too (`modules/secrets/README.md`) |
| `net.leibman:thicket-clipboard-apple_native0.5_3` | text on the general pasteboard, `NSPasteboard` / `UIPasteboard` (`thicket-clipboard` and the Apple renderer come with it); no Swift, and it links UIKit or AppKit itself |
| `net.leibman:thicket-share-apple_native0.5_3` | the share sheet on macOS and iOS, `NSSharingServicePicker` / `UIActivityViewController` (`thicket-share` comes with it); no Swift, and it links UIKit or AppKit itself |
| `net.leibman:thicket-haptics-apple_native0.5_3` | haptic taps: iOS's feedback generators, macOS's `NSHapticFeedbackManager` (`thicket-haptics` comes with it); no Swift |
| `net.leibman:thicket-http-apple_native0.5_3` | an sttp `SyncBackend` over `URLSession`, for iOS (no libcurl there), with its own Swift library inside the jar |
| `net.leibman:thicket-http-gtk_native0.5_3` | an sttp `SyncBackend` over libcurl, in place of sttp's `CurlBackend`; libcurl is loaded at run time, so no `-dev` package |
Expand Down Expand Up @@ -178,4 +179,4 @@ renderers and the platform modules that are not in `root`: `thicket-http-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-camera-android` and `thicket-share-android`.
`thicket-camera-android`, `thicket-share-android` and `thicket-share-apple`.
6 changes: 5 additions & 1 deletion docs/16-device-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,11 @@ Every service gets a gallery section and self-test checks on every host where it
text and files through the chooser. Files are served by Thicket's own `ContentProvider`
(owner's decision 2026-11-01: not AndroidX's `FileProvider`), which the app declares in its
manifest. The gallery is its own share target, and the share sheet's own read of the file
shows the grant works.
shows the grant works. *Apple done 2026-11-02 (#134): `thicket-share-apple`, a C helper (no
Swift; the subject through a `UIActivityItemSource` class made at run time). On iOS an
XCUITest taps "Copy" in the `UIActivityViewController` and `simctl pbpaste` reads the text;
on macOS the `NSSharingServicePicker` popover is found, its offered services read and it is
closed, but no service can be driven (its list is drawn out of process).*
6. **Tier 3** as separate designs, live camera preview first if wanted. *The owner wants tier 3
(2026-11-01); the camera preview's design is `docs/17-camera-preview.md`, approved with every
recommendation (2026-11-01); the embedding point is next.*
45 changes: 45 additions & 0 deletions docs/decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,51 @@ Go decision (see `08` §8.1) is made after S1, S2, S3 have reports.

## Decision log

- 2026-11-02 — **Apple share: `thicket-share-apple`, a C helper over the Objective-C runtime,
no Swift; `UIActivityViewController` on iOS, `NSSharingServicePicker` on macOS** (#134, the
Apple half of docs/16 §16.10 item 5).
- **C, and the subject kept.** iOS asks for a subject through `UIActivityItemSource`, a
protocol, which looked like the one reason for Swift. The helper makes the class at run
time instead (`objc_allocateClassPair`, three `class_addMethod`s, `class_addProtocol`), with
the text and subject as associated objects: about 30 lines, against a Swift library, a build
script, an archive in the jar and a shim-gen ABI. So `thicket_share.c` is compiled by Scala
Native's own clang, as `thicket_pasteboard.c` (#123) is. macOS has no subject for a text and
drops it.
- **Presentation.** iOS presents over whatever is on top of the key window (a Thicket sheet
included), anchored at the top view's centre on an iPad. macOS shows the picker below the key
window's content view. That is a popover (`_NSPopoverWindow`, measured on macOS 27): it is
not modal, the call returns at once, and the service list inside is an `NSRemoteView`
drawn by another process.
- **Files.** A file is copied first, through `SharedFiles`, into `<cache>/thicket-shared`, and
that copy's URL is shared. The copy is made on the calling thread, so a large file blocks
the UI while it copies. Android copies on a worker; this keeps errors (a missing file)
synchronous to the caller. The type is the extension's, as Apple reads it; `mimeType` is
kept beside the copy, but nothing on Apple asks for it. With no window to show it from, a
call throws `IllegalStateException`. `AppleShare(storage.dirs.cache)` in both galleries.
- **What the self-test drives** (`GalleryShareChecks`). macOS: the picker's window is found
(up in 442 ms for the text, 53 ms for the file), and the services its delegate was offered
are read: 5 for the text (Messages, Notes, Freeform, Journal, Reminders), 9 for the file
(AirDrop, Mail, …). AppKit asks the delegate twice per picker (5 then 0 services for the
text), so the titles accumulate. The picker is closed with `close`, and the delegate hears
no choice (about 530 ms). **No macOS service is driven:** there is no "Copy" among them, the
remote view takes no clicks from the app, and driving it from outside needs the
Accessibility permission (`AXIsProcessTrusted` is false here). iOS: the
`UIActivityViewController` is on top. The item source answers UIKit's questions with the
text, and with the subject for Mail (Mail itself is not on the simulator). `DRIVE share-copy`
has an XCUITest tap the sheet's "Copy" cell; the sheet goes, the pasteboard's change count
rises, and `simctl pbpaste`, outside the app, reads the shared text. On both platforms the
file arrives as a copy with its bytes and type.
- **Controls.** With the presentation call removed, macOS failed 6 checks and iOS 7, every
"appears" among them. With the item source answering another text and no subject, iOS failed
the two item-source checks and the `share-copy` DRIVE: `pbpaste` did not read the shared
text.
- **The tapper stops at the tap.** On this Mac, XCTest's tear-down took 300–308 s after every
tap (3 runs: "Tear Down", with nothing under it). The location checks' 30 s waits ran out
behind it. So `tap.sh` now returns when the test prints its line, and stops xcodebuild:
7.2 s for a tap, 25.7 s for a miss. A `<bundle id>|<label>` form taps a cell in an app,
after activating it. Cells only: the gallery has a "Copy" button of its own, which
otherwise matched first.

- 2026-11-02 — **Apple CI: a notifications read that times out is "no answer", not Denied**
(#128). Every failed `apple.yml` run since #132 merged (5 of 5 checked: 41391530485,
41390412068, 41374569722, 41374441105, 41374248305) failed one step, `ios-gallery`, on
Expand Down
5 changes: 4 additions & 1 deletion examples/gallery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ target ("Thicket gallery inbox", `ShareTargetActivity`): `build.sh` taps it in t
chooser (`DRIVE share-pick`), and it reads what it was given, the file through the URI
Thicket's provider served. The inbox is the gallery itself, which needs no grant, so the
self-test also requires the share sheet, another app, to have read the file through it. On
GTK the section says there is no share sheet.
GTK the section says there is no share sheet. On macOS the self-test finds the picker's popover,
reads the services it was offered and closes it; on iOS it finds the `UIActivityViewController`,
asks its item for the text and subject, and has an XCUITest tap "Copy" in it (`DRIVE share-copy`),
after which `simctl pbpaste` must read the shared text (#134).

When the desktop is locked, GNOME suspends every window and the Device section's foreground
check fails. A private headless shell avoids that:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ object GallerySelfTest {

storageChecks(() =>
deviceChecks(() =>
locationChecks(() => motionChecks(() => clipboardChecks(() => sheet(all)(() => bigList(() => finish())))))
locationChecks(() =>
motionChecks(() => shareChecks(() => clipboardChecks(() => sheet(all)(() => bigList(() => finish())))))
)
)
)
}
Expand Down Expand Up @@ -276,6 +278,17 @@ object GallerySelfTest {
private def motionChecks(next: () => Unit): Unit =
GalleryMotionChecks.run(checker, () => AppleInspect.allTexts(AppleApp.rootHandle), motion)(next)

/** The share sheet (#134), in [[GalleryShareChecks]]. Before the clipboard's: on iOS it taps "Copy" in the sheet, and
* the clipboard's own last copy must be the pasteboard's text when the run ends (`bin/verify-apple.sh`).
*/
private def shareChecks(next: () => Unit): Unit =
GalleryShareChecks.run(
checker,
label => buttonIn(AppleInspect.all(AppleApp.rootHandle), label).exists(AppleInspect.click),
() => AppleInspect.allTexts(AppleApp.rootHandle),
storage.map(_.dirs.cache)
)(next)

/** The clipboard and haptics (#123), the GTK host's `clipboardChecks` asked of Apple. "Copy" then "Paste", twice,
* through the general pasteboard: each paste must show that round's copy, so a pasteboard that kept the first text,
* or never took one, fails. Each copy must also raise the pasteboard's change count, which only a real write does.
Expand Down
Loading
Loading
0