8000 Apple motion: thicket-motion-ios over CMMotionManager; macOS Motion.unavailable (#120) by rleibman · Pull Request #137 · rleibman/thicket · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b7d79dd
WIP #114: thicket-device-apple, its Swift library and the thk_dev ABI
Oct 30, 2026
606f769
WIP #114: the Apple galleries' device checks
Oct 30, 2026
9a78bbb
WIP #114: iOS DRIVE hooks, XCUITest tapper; iOS gallery 191/191 on iP…
Oct 30, 2026
8caddf6
WIP #114: verify-apple shim-device step, sbt-thicket thicketDeviceApp…
Oct 30, 2026
df5caf5
WIP #114: docs, decision log, scalafmt exclude for the generated Devi…
Oct 30, 2026
864fdce
WIP #114: catch a leftover refusal (notYetAsked, failed DRIVE fails),…
Oct 30, 2026
9cff276
WIP #114: uninstall at the end of a fresh-install run instead of a se…
Oct 31, 2026
7494924
#114: macOS measured unlocked: gallery 195 (185 + 10), occlusion cont…
Oct 31, 2026
5c48dc2
WIP #120: thicket-motion-ios: MotionAbi (thk_mot_*, 4 functions), Swi…
Oct 31, 2026
789e89a
WIP #120: the gallery's Motion section on Apple: IosMotion on iOS, Mo…
Oct 31, 2026
ef811a1
WIP #120: thicketMotionIos in sbt-thicket; MotionShim.scala excluded …
Oct 31, 2026
84666e8
Merge main into #132; storageChecks gets its Scaladoc back (Copilot r…
Oct 31, 2026
9522d78
WIP #120: docs: decision log, docs/09 §9.11, 12, 14, 16, motion README
Nov 1, 2026
3f6ea69
Merge origin/issue/114-apple-device (main, clipboard and haptics) int…
Nov 1, 2026
9fb76ed
#120: the verify-apple results in the decision log
Nov 1, 2026
279bce8
Merge main (pickers #131, camera #133) into #132
rleibman Nov 1, 2026
cc3ee5a
Merge main (pickers #131, camera #133) into #137
rleibman Nov 1, 2026
5979dc2
Merge main (Apple clipboard/haptics #127, docs/17 #136 #139) into #132
rleibman Nov 2, 2026
cbe606d
Merge #132's branch (with main: #127, #136, #139) into #137
rleibman Nov 2, 2026
4d03133
Apple device lifecycle and permissions: thicket-device-apple, the gal…
rleibman Nov 2, 2026
7e866f2
Share: thicket-share and -android, files served by Thicket's own prov…
rleibman Nov 2, 2026
34100f2
Apple location: thicket-location-apple over CLLocationManager (iOS); …
rleibman Nov 2, 2026
b68193e
Merge main into #137, re-applying Apple motion on top of #132 and #13…
Nov 2, 2026
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: 2 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ project.excludeFilters = [
# Generated by tools/shim-gen; GenerateSpec compares it byte for byte.
"modules/renderer-apple/src/main/scala/thicket/renderer/apple/Shim.scala"
"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"
]

maxColumn = 120
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,12 @@ modules/
secrets/ tokens and passwords in the platform's secure store; secrets-gtk/, secrets-android/, secrets-apple/
device/ the app's lifecycle and permissions; device-gtk/, device-android/
location/ the device's position; location-android/ (GTK: Location.unavailable)
motion/ acceleration, rotation rate, attitude; motion-android/ (GTK: Motion.unavailable)
motion/ acceleration, rotation rate, attitude; motion-android/, motion-ios/ (GTK, macOS: Motion.unavailable)
clipboard/ text on the system clipboard; clipboard-gtk/, clipboard-android/, clipboard-apple/
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)
renderer-gtk/ GTK4 (Scala Native)
renderer-android/ android.view (Scala on ART)
renderer-apple/ AppKit + UIKit (Scala Native + Swift shim)
Expand Down Expand Up @@ -361,8 +362,8 @@ SELFTEST=1 examples/todo-android/build.sh
xvfb; the Apple self-tests run on a self-hosted Mac (`apple.yml`). Counts as of 2026-10-21:
signals 30, core 170, effect-zio 25, storage 14, sqlite 2 and secrets 2 per backend,
storage-gtk 4, storage-apple 4, secrets-gtk 2, http-gtk 5, http-android 5, device 8,
location 7, motion 5, clipboard 1, haptics 2, pickers 4 and camera 2 per backend, shim-gen 15,
sbt-thicket 9; GTK 137 + 69 self-test checks, Android 86 + 84 (2026-10-30, the gallery's with
location 7, motion 5, clipboard 1, haptics 2, pickers 4, camera 2 and share 5 per backend, shim-gen 15,
sbt-thicket 9; GTK 138 + 69 self-test checks, Android 90 + 84 (2026-10-30, the gallery's with
the HTTP checks and every device section's),
the HTTP checks on Linux 12.

Expand Down
9 changes: 7 additions & 2 deletions bin/verify-apple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
# toolchain xcrun swiftc / xcodebuild versions, recorded with the result
# shim-macos compile Shim+AppKit.swift (build-shim.sh macos)
# 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)
# 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
# macos-gallery THICKET_GALLERY_SELFTEST=1 gallery-macos, twice: its secret stored, then kept;
# after each, pbpaste must read its last copy (the user's text is put back)
# macos-todo THICKET_SELFTEST=1 todo-macos
# 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), then
# simctl pbpaste must read its last copy
# 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
# 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 @@ -180,6 +183,8 @@ sbt shutdown >/dev/null 2>&1 || true
run toolchain sh -c 'sw_vers; xcodebuild -version; xcrun swiftc --version'
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 abi sbt --error shimGen/testFull
run secrets sbt --error secretsApple/testFull
run link link_all
Expand Down
109 changes: 106 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,39 @@ lazy val deviceAndroid = project
.dependsOn(device.jvm, rendererAndroid)
.settings(commonSettings, name := "thicket-device-android", scalacOptions ++= Seq("-release", "17"))

/** Lifecycle and permissions on macOS and iOS (#114): scene notifications on iOS, NSApp's occlusion state on macOS,
* and each servi 10BC8 ce's own authorisation API. A Swift library of its own (`shim/`, `libthicketdevice.a`) carried in the
* jar like `httpApple`'s, so an app without it links none of it nor the frameworks it names. `core` for
* `GcState.guarded`: the library calls back into Scala on the main thread. In `platforms`; building the Swift needs
* Xcode, so only a Mac links it.
*/
lazy val deviceApple = project
.in(file("modules/device-apple"))
.enablePlugins(AutomateHeaderPlugin, com.github.sbt.git.GitVersioning, ScalaNativePlugin)
.dependsOn(device.native, core.native)
.settings(commonSettings, name := "thicket-device-apple")
// Generated by shimGen and compared byte for byte, like the renderer's `Shim.scala`.
.settings(headerSources / excludeFilter := HiddenFileFilter || "DeviceShim.scala")
.settings(
publish / skip := !isMac,
Compile / packageBin / mappings ++= {
val shim = (ThisBuild / baseDirectory).value / "modules" / "device-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"device-apple build-shim.sh $target failed with exit $code")
}
Seq(
shim / "build" / "libthicketdevice.a" -> "thicket-device-apple/macos/libthicketdevice.a",
shim / "build-ios" / "libthicketdevice.a" -> "thicket-device-apple/ios-sim/libthicketdevice.a",
shim / "include" / "thicket_device.h" -> "thicket-device-apple/include/thicket_device.h"
).map((f, path) => conv.toVirtualFile(f.toPath) -> path)
}
}
)

/** The device's position (`docs/16` §16.3, §16.10 item 4): `Location`, `Fix`, `Accuracy`, the lifecycle-aware
* `Location(provider, lifecycle)`, and a fake provider for tests. GTK and macOS use `Location.unavailable`.
*/
Expand All @@ -632,6 +665,16 @@ lazy val locationAndroid = project
.dependsOn(location.jvm, deviceAndroid)
.settings(commonSettings, name := "thicket-location-android", scalacOptions ++= Seq("-release", "17"))

/** Location on iOS, from `CLLocationManager` (#118). Scala only: the manager and its delegate are in
* `thicket-device-apple`'s Swift library, beside the location permission, which needs the same delegate. macOS uses
* `Location.unavailable` (`docs/16` §16.9, decision 7). In `platforms`; only a Mac links it.
*/
lazy val locationApple = project
.in(file("modules/location-apple"))
.enablePlugins(AutomateHeaderPlugin, com.github.sbt.git.GitVersioning, ScalaNativePlugin)
.dependsOn(location.native, deviceApple)
.settings(commonSettings, name := "thicket-location-apple", publish / skip := !isMac)

/** The motion sensors (`docs/16` §16.3, §16.10 item 4): `Motion`'s acceleration, rotation rate and attitude, run only
* while the app is in front, and a fake provider for tests. GTK and macOS use `Motion.unavailable`.
*/
Expand All @@ -651,6 +694,34 @@ lazy val motionAndroid = project
.dependsOn(motion.jvm, deviceAndroid)
.settings(commonSettings, name := "thicket-motion-android", scalacOptions ++= Seq("-release", "17"))

/** Motion on iOS (#120), from `CMMotionManager`: a Swift library of its own (`shim/`, `libthicketmotion.a`, iOS only)
* carried in the jar like `deviceApple`'s, so an app without it links none of it nor CoreMotion. macOS has no
* `CMMotionManager` and uses `Motion.unavailable`. In `platforms`; building the Swift needs Xcode.
*/
lazy val motionIos = project
.in(file("modules/motion-ios"))
.enablePlugins(AutomateHeaderPlugin, com.github.sbt.git.GitVersioning, ScalaNativePlugin)
.dependsOn(motion.native, deviceApple, core.native)
.settings(commonSettings, name := "thicket-motion-ios")
// Generated by shimGen and compared byte for byte, like the renderer's `Shim.scala`.
.settings(headerSources / excludeFilter := HiddenFileFilter || "MotionShim.scala")
.settings(
publish / skip := !isMac,
Compile / packageBin / mappings ++= {
val shim = (ThisBuild / baseDirectory).value / "modules" / "motion-ios" / "shim"
val conv = fileConverter.value
if !isMac then Seq.empty
else {
val code = scala.sys.process.Process(Seq("bash", (shim / "build-shim.sh").getAbsolutePath, "ios-sim"), shim).!
if code != 0 then sys.error(s"motion-ios build-shim.sh ios-sim failed with exit $code")
Seq(
shim / "build-ios" / "libthicketmotion.a" -> "thicket-motion-ios/ios-sim/libthicketmotion.a",
shim / "include" / "thicket_motion.h" -> "thicket-motion-ios/include/thicket_motion.h"
).map((f, path) => conv.toVirtualFile(f.toPath) -> path)
}
}
)

/** Text on the system clipboard (`docs/16` §16.3, §16.10 item 5), and an in-memory one for tests. */
lazy val clipboard = crossProject(JVMPlatform, NativePlatform)
.crossType(CrossType.Full)
Expand Down Expand Up @@ -736,6 +807,27 @@ lazy val cameraAndroid = project
.dependsOn(camera.jvm, rendererAndroid)
.settings(commonSettings, name := "thicket-camera-android", scalacOptions ++= Seq("-release", "17"))

/** Handing text or a file to another app through the platform's share sheet (`docs/16` §16.3, §16.10 item 5), and the
* shared copies' store. GTK uses `Share.unavailable`.
*/
lazy val share = crossProject(JVMPlatform, NativePlatform)
.crossType(CrossType.Full)
.in(file("modules/share"))
.dependsOn(device)
.enablePlugins(AutomateHeaderPlugin, com.github.sbt.git.GitVersioning)
.settings(commonSettings, zioTestFramework, name := "thicket-share")
.jvmSettings(libraryDependencies ++= zioTestJvm, scalacOptions ++= Seq("-release", "17"))
.nativeSettings(libraryDependencies ++= zioTestNative)

/** Share on Android: `ACTION_SEND` through the chooser, files served by Thicket's own `ThicketFileProvider`, which the
* app declares in its manifest (owner's decision, 2026-11-01: not AndroidX's `FileProvider`).
*/
lazy val shareAndroid = project
.in(file("modules/share-android"))
.enablePlugins(AutomateHeaderPlugin, com.github.sbt.git.GitVersioning)
.dependsOn(share.jvm, rendererAndroid)
.settings(commonSettings, name := "thicket-share-android", scalacOptions ++= Seq("-release", "17"))

/** The clipboard on macOS and iOS: `NSPasteboard` and `UIPasteboard` (#123), through a small C helper that Scala
* Native's own clang compiles (`resources/scala-native/thicket_pasteboard.c`) and that sends its few Objective-C
* messages through the runtime. No Swift. Depends on `rendererApple` for `postToUi`, as `clipboardGtk` does on its
Expand Down Expand Up @@ -863,7 +955,7 @@ lazy val galleryShared = crossProject(JVMPlatform, NativePlatform)
.in(file("examples/gallery/shared"))
// effect-zio too: the gallery runs one real effect, so every host proves it installed a UI-thread poster.
// storage and sqlite: the device services' section; each host supplies its platform's implementation.
.dependsOn(core, effectZio, storage, sqlite, secrets, device, location, motion, clipboard, haptics, pickers, camera)
.dependsOn(core, effectZio, storage, sqlite, secrets, device, location, motion, clipboard, haptics, pickers, camera, share)
.enablePlugins(AutomateHeaderPlugin, com.github.sbt.git.GitVersioning, BuildInfoPlugin)
.settings(thicketBuildInfo("example.gallery.buildinfo", buildTime = true))
.settings(commonSettings, name := "thicket-gallery-shared", publish / skip := true)
Expand Down Expand Up @@ -905,6 +997,7 @@ lazy val galleryAndroid = project
hapticsAndroid,
pickersAndroid,
cameraAndroid,
shareAndroid,
httpChecks.jvm,
httpAndroid
)
Expand All @@ -925,11 +1018,15 @@ 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, clipboardApple, hapticsApple)
.dependsOn(rendererApple, galleryShared.native, storageApple, secretsApple, deviceApple, locationApple, clipboardApple, hapticsApple)
.settings(commonSettings)
.settings(appleNativeSettings)
.settings(galleryAppleSharedSources)
.settings(appleSystemSqlite)
// thicket-device-apple's Swift library (#114): `modules/device-apple/shim/build-shim.sh` builds it.
.settings(
nativeConfig ~= thicket.sbt.ThicketNativeFlags.appleDevice(file("modules") / "device-apple" / "shim" / "build")
)
.settings(
name := "gallery-macos",
publish / skip := true,
Expand All @@ -940,7 +1037,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, clipboardApple, hapticsApple)
.dependsOn(rendererApple, galleryShared.native, storageApple, secretsApple, deviceApple, locationApple, motionIos, clipboardApple, hapticsApple)
.settings(commonSettings)
.settings(iosNativeSettings)
.settings(galleryAppleSharedSources)
Expand Down Expand Up @@ -1109,14 +1206,18 @@ lazy val platforms = project
secretsApple,
deviceGtk,
deviceAndroid,
deviceApple,
locationAndroid,
locationApple,
motionAndroid,
motionIos,
clipboardGtk,
clipboardAndroid,
hapticsAndroid,
pickersGtk,
pickersAndroid,
cameraAndroid,
shareAndroid,
clipboardApple,
hapticsApple,
examplesShared.jvm,
Expand Down Expand Up @@ -1178,6 +1279,8 @@ lazy val root = project
pickers.native,
camera.jvm,
camera.native,
share.jvm,
share.native,
httpGtk,
httpAndroid,
shimGen,
Expand Down
10 changes: 10 additions & 0 deletions docs/09-open-questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,13 @@ should not be made until M1.
run puts a fresh marker in the coverage compile's options, so it never hits the cache. The
"inc_compile_3.zip is missing" failures from the earlier attempts did not recur with this
approach, including after deleting `target/out`; what caused them was not established.

## 9.11 Opened by #120 (2026-10-31)

- **Do iOS and Android agree on motion's signs?** The iOS side is not measured: the simulator
has no motion hardware. Acceleration is negated on iOS by reasoning (Core Motion reports gravity as
(0, 0, -1) g flat, Android the support force, (0, 0, +9.81) m/s²); a device flat on a table
settles it. Attitude is Core Motion's roll, pitch and yaw as they come: yaw is zero where
updates started, not north as on Android, and whether roll and pitch turn the same way as
`getOrientation`'s is open. Either `Attitude` documents the difference or iOS converts
(`xMagneticNorthZVertical`, and signs measured on both).
Loading
Loading
0