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

Apple share: thicket-share-apple, UIActivityViewController (iOS) and NSSharingServicePicker (macOS) (#134) - #141

Merged
rleibman merged 6 commits into
mainfrom
issue/134-apple-share
Nov 3, 2026
Merged

rleibman merged 6 commits into
mainfrom
issue/134-apple-share

Conversation

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

Closes #134.

What

thicket-share-apple: Share.text(text, subject), Share.file(path, mimeType), availability.

  • iOS: a UIActivityViewController, presented over whatever is on top of the key window (anchored for an iPad popover).
  • macOS: an NSSharingServicePicker below the key window's content view.
  • C helper over the Objective-C runtime, no Swift (resources/scala-native/thicket_share.c), as in Apple clipboard and haptics: NSPasteboard / UIPasteboard, UIImpactFeedbackGenerator #123. The subject is kept. UIActivityItemSource is a protocol, but the helper builds a class that adopts it at run time (objc_allocateClassPair, class_addMethod, class_addProtocol). That is about 30 lines of C, against a Swift library, a build script, an archive in the jar and a shim-gen ABI. macOS has no subject for a text, so it drops it.
  • A file is shared as a copy under <cache>/thicket-shared, through SharedFiles, and the copy's URL is what is handed over. The copy is made on the calling thread.
  • Both galleries pass share = Some(AppleShare(storage.dirs.cache)). shareApple is in platforms.

Measured

The checks are in examples/gallery/apple-shared/.../GalleryShareChecks.scala.

macOS (8 checks):

  • The picker's window (_NSPopoverWindow holding an NSRemoteView) appears: 136–442 ms for the text, 23–53 ms for the file.
  • The picker's delegate is offered services: 5 for the text (Messages, Notes, Freeform, Journal, Reminders) and 9 for the file (AirDrop, Mail, …). AppKit asks the delegate twice per picker, so the titles accumulate.
  • close takes the picker down in about 530 ms, and the delegate hears no choice.
  • The file is a copy with its bytes and type.

iOS, "iPhone 18 Pro" (9 checks):

  • A UIActivityViewController is on top within 39–212 ms.
  • Its item gives UIKit the text, and gives Mail the subject.
  • DRIVE share-copy has an XCUITest tap the sheet's "Copy" cell. The sheet goes, the change count rises, and xcrun simctl pbpaste reads "Shared from the Thicket gallery" from outside the app.
  • The file is a copy with its bytes and type.
  • Each sheet goes when dismissed, in about 1.1 s.

Gallery totals: macOS 208 checks (204 with the screen locked, in verify-apple); iOS 216. All passed.

Controls (the code broken on purpose, then restored)

  • Presentation call removed: macOS failed 6 checks and iOS 7, every "the share sheet appears" check among them. On iOS the tapper also found no "Copy".
  • Item source answering another text, with no subject: iOS failed the 2 item-source checks. pbpaste did not read the shared text, so the share-copy DRIVE failed.

bin/verify-apple.sh "iPhone 18 Pro" (run while holding the shared lock)

17 of 18 steps passed. ios-gallery failed for reasons outside this change:

  • Full run: the simulator was "Shutting Down" (simctl error 405) during the location DRIVE. Nothing in the run itself shut it down.
  • Step re-run alone on a fresh boot: the only failure was known trap (2), "notifications start Denied" right after a boot. All Share checks passed.
  • Re-run on the warm simulator: ALL CHECKS PASSED (216), and simctl pbpaste matched the clipboard section's last copy.

Tapper change (examples/ios-host/tapper)

  • On this Mac, XCTest's tear-down took 300–308 s after every tap, in 3 runs. The location checks' 30 s waits ran out behind it.
  • tap.sh now returns as soon as the test prints its line, then stops xcodebuild. A tap takes 7.2 s and a miss 25.7 s.
  • A new <bundle id>|<label> form activates an app and tap 8000 s a cell with that label. It only looks at cells because the gallery has its own "Copy" button, which otherwise matched first.
  • The tap is aimed at the cell's centre. element.tap() looks the cell up again after tapping, and fails because the sheet has already closed.
  • The tapper is rebuilt when its Swift source is newer than the build.

Not measured / not driven

  • macOS: no service is driven. The list contains no "Copy", the list is drawn by another process, and reaching it from outside needs the Accessibility permission (AXIsProcessTrusted is false here).
  • iOS: Mail, Messages and AirDrop are not driven, and Mail is not on the simulator. The subject is checked by asking the item source exactly as UIKit asks it.
  • iOS file share: only shown and dismissed. The file was not handed to a receiving app.
  • Not run: an iPad (the popover anchor) and a physical device.
  • In the item-source control, the app saw the change count rise, but pbpaste still read the earlier text for 5 s. I did not dig further; the check failed as it should.

🤖 Generated with Claude Code

Roberto Leibman and others added 5 commits November 2, 2026 07:08
…ery share checks (#134)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…osed with no choice (#134)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the tap (#134)

The XCUITest's tear-down took 300-308 s after each tap here (3 runs); tap.sh
now returns at the tap's own line: 7.15 s for a tap, 25.7 s for a miss.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

🔵 Needs a closer look

The change relies on Apple-only UI and Objective-C runtime integration (including share-sheet/picker presentation and potential ABI/memory/threading concerns) that cannot be compiled or runtime-validated in this Linux review environment, so it needs confirmation on macOS/iOS toolchains before merge.

No open issues 🎉

What changed in this PR

Adds Apple (iOS + macOS) support for Thicket’s Share device service via a new Scala Native module (thicket-share-apple) that presents the system share UI using an Objective‑C runtime C helper, wires the service into the Apple galleries, expands self-test coverage, and updates build/docs accordingly.

Changes:

  • Introduces thicket-share-apple implementing Share.text, Share.file, and availability (iOS UIActivityViewController, macOS NSSharingServicePicker) using a C helper over the Objective‑C runtime.
  • Adds/extends Apple gallery self-tests for share-sheet appearance/behavior (including iOS “Copy” flow via the XCTest tapper) and integrates AppleShare into iOS/macOS gallery apps.
  • Updates docs and build configuration to include the new module and reflect device-service status/release artifacts.

Outstanding review comments to address (all moderate):

  • examples/ios-host/tapper/tap.sh: rebuild check relies on directory mtime for build/Build/Products, which is not a reliable up-to-date signal.
  • modules/share-apple/src/main/resources/scala-native/thicket_share.c: macOS thk_share_dismiss may report success even when no popover is visible due to picker remaining non-NULL after close.
  • modules/share-apple/src/main/scala/thicket/share/apple/AppleShare.scala: pruning of shared copies is only triggered on file(...), despite docs indicating pruning “at each share”.
File Summary
README.md Notes/links share-apple within the module set.
modules/​share/​README.md Documents Apple share behavior and the Apple gallery self-test approach.
modules/​share-apple/​src/​main/​scala/​thicket/​share/​apple/​AppleShare.scala Implements AppleShare (Scala Native) and related test hooks; manages shared file copies under cache.
modules/​share-apple/​src/​main/​resources/​scala-native/​thicket_share.c Objective‑C runtime helper implementing iOS/macOS share presentation + self-test introspection helpers.
examples/​ios-host/​tapper/​TapperUITests/​TapperUITests.swift Extends tapper to activate an app and tap a labeled cell (used for share-sheet “Copy”).
examples/​ios-host/​tapper/​tap.sh Updates tapper runner to stop early (avoid long teardown) and adds rebuild logic/`
examples/​gallery/​README.md Describes Apple share self-test strategy on macOS/iOS.
examples/​gallery/​macos/​src/​main/​scala/​example/​gallery/​GalleryMac.scala Wires AppleShare(storage.dirs.cache) into macOS gallery services.
examples/​gallery/​ios/​src/​main/​scala/​example/​gallery/​GalleryIos.scala Wires AppleShare(storage.dirs.cache) into iOS gallery services.
examples/​gallery/​ios/​ios-app/​build-app.sh Adds/updates drive steps for iOS share checks (including “Copy” + pasteboard validation).
examples/​gallery/​apple-shared/​src/​main/​scala/​example/​gallery/​GalleryShareChecks.scala Adds Apple share checks (sheet appearance, dismissal, item-source/subject behavior, shared-file copy verification).
examples/​gallery/​apple-shared/​src/​main/​scala/​example/​gallery/​GallerySelfTest.scala Integrates share checks into the Apple self-test flow.
docs/​decisions.md Records the Apple share implementation decision and measured behavior.
docs/​16-device-services.md Updates device-services progress notes to reflect Apple Share support.
docs/​14-releasing.md Adds thicket-share-apple to release documentation/artifact lists.
docs/​12-component-status.md Updates component status/check counts to reflect Share on macOS/iOS.
build.sbt Adds shareApple project and wires it into platforms and Apple gallery dependencies.

This pull request requires changes.

Review effort: Balanced

Conflict only in docs/decisions.md: both 2026-11-02 entries kept. The rest
merged cleanly. Checked here: sbt scalafmtAll and platforms/Test/compile, 0
errors. Not checked: the Apple self-tests (they need the Mac).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rleibman
rleibman merged commit b0cefae into main Nov 3, 2026
1 of 2 checks passed
rleibman added a commit that referenced this pull request Nov 3, 2026
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 added a commit that referenced this pull request Nov 3, 2026
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>
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 share: UIActivityViewController (iOS), NSSharingServicePicker (macOS)

2 participants

0