8000 Apple device lifecycle and permissions: thicket-device-apple, the galleries' Device section (#114) by rleibman · Pull Request #132 · 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 @@ -13,6 +13,7 @@ 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"
]

maxColumn = 120
Expand Down
7 changes: 5 additions & 2 deletions bin/verify-apple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
# 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)
# 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 +182,7 @@ 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 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
8 10BC8
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 service'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 Down Expand Up @@ -925,11 +958,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, 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 +977,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, clipboardApple, hapticsApple)
.settings(commonSettings)
.settings(iosNativeSettings)
.settings(galleryAppleSharedSources)
Expand Down Expand Up @@ -1109,6 +1146,7 @@ lazy val platforms = project
secretsApple,
deviceGtk,
deviceAndroid,
deviceApple,
locationAndroid,
motionAndroid,
clipboardGtk,
Expand Down
10 changes: 6 additions & 4 deletions docs/12-component-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ every remaining entry before it is built, not after.
| App directories and preferences | `modules/storage`, `storage-gtk`, `storage-android`, `storage-apple` | done on GTK (XDG directories, `FilePreferences`), Android (internal storage, `SharedPreferences`), and macOS and iOS (Application Support, Caches and the per-user temporary directory under the bundle id, matching Foundation's on both; `FilePreferences`, 2026-10-22, #98); a value reads back as the type it was written as on all of them. `docs/16` §16.6 |
| SQLite, through plain JDBC | `modules/sqlite`, `sqlite-android` | done on GTK (`scala-native-jdbc-sqlite` 0.0.7) and Android (Thicket's driver over `android.database.sqlite`). Every driver runs the same 17 `JdbcConformance` checks: xerial on the JVM and the Android driver pass all of them. The Native driver fails exactly 2, both upstream: batches and `setFetchSize` are unimplemented. (0.0.6 failed 3 more, swallowed errors, fixed upstream in 0.0.7.) Magnum works on Native; on Android it needs a one-line upstream fix (`docs/16` §16.5). macOS and iOS (#98, 2026-10-22, measured on 0.0.6): the same driver over the system `libsqlite3`, failing the same 5 that 0.0.6 failed on Linux, on macOS (`sqliteNative`) and on the iOS simulator (gallery self-test); not yet re-measured on 0.0.7. The bundled amalgamation would cost 1.09 MiB of the iOS app. `docs/16` §16.5 |
| Secrets | `modules/secrets`, `secrets-gtk`, `secrets-android`, `secrets-apple` | done on GTK (the Secret Service through libsecret, loaded with `dlopen`, so it's optional at run time: absent, `open` says why) and Android (AES-GCM under an Android Keystore key). Both pass all 11 `SecretsConformance` checks, and a secret written on one run is read back on the next. Done on Apple too (#108): the Keychain, through a C helper Scala Native compiles. The iOS simulator uses the app's data-protection keychain, which needs the host's entitlements. An unsigned Mac binary gets the login keychain, and a rebuilt binary can't read what an earlier build stored. 11/11 conformance on macOS and the iOS simulator, stored then kept in both galleries. `modules/secrets/README.md` |
| Lifecycle and permissions | `modules/device`, `device-gtk`, `device-android` | done on GTK and Android (2026-10-28) — `AppLifecycle.state` (Foreground while a `ThicketActivity` is started, or while the GTK window is shown and not minimised or suspended) and `onTerminate`; `Permissions` (Android's dialog, one at a time; an undeclared permission throws; GTK grants all). The gallery's Device section drives them through each host. Apple is a Mac issue. `modules/device/README.md` |
| Lifecycle and permissions | `modules/device`, `device-gtk`, `device-android`, `device-apple` | done on GTK and Android (2026-10-28), Apple (2026-10-30) — `AppLifecycle.state` (Foreground while a `ThicketActivity` is started, or while the GTK window is shown and not minimised or suspended) and `onTerminate`; `Permissions` (Android's dialog, one at a time; an undeclared permission throws; GTK grants all). The gallery's Device section drives them through each host. Apple (2026-10-30, #114): `thicket-device-apple`, scene notifications on iOS and `NSApp`'s occlusion state on macOS, each service's authorisation API; a missing `Info.plist` usage string throws. `modules/device/README.md` |
| Location | `modules/location`, `location-android` | done on Android (2026-10-30) — the framework's `LocationManager` (GPS for `Fine` when fine permission is granted, else network), listened to only while the app is in front; `availability` says `NeedsPermission` or why it's `Unavailable`. GTK uses `Location.unavailable` (`docs/16` §16.9, decision 7). The gallery's Location section is driven with `adb emu geo fix`. Apple is a Mac issue. `modules/location/README.md` |
| 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`. Apple (iOS) is a Mac issue. `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` |
Expand Down Expand Up @@ -365,7 +365,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` | 15 |
| `shimGen` | 30 (the `thk_dev` ABI's 7 included, 2026-10-30) |
| `sbtThicket` | 9 |

Measured 2026-10-20 with `sbt --error testFull`, which `sbt checkLinux` and CI run; the
Expand All @@ -379,8 +379,10 @@ Clipboard and haptics section's 3 and 5, and the Pickers and camera section's 6
The Android gallery's `build.sh` also checks that Back runs the terminate hook. HTTP on Linux: `examples/http/selftest.sh linux`,
**12**. Apple gallery (2026-10-22, #98): macOS **174**, iOS simulator **168**,
each with six storage checks; 2026-10-27 (#108): macOS **185**, iOS simulator **179**, the two
secrets checks included; 2026-10-30 (#123): macOS **188**, iOS simulator ("iPhone Air") **182**,
the Clipboard and haptics section's 3 included.
secrets checks included; 2026-10-30 (#114): iOS simulator **191** (179 + 12, the Device section),
macOS **195** (185 + 10; 191 with the screen locked, where the lifecycle checks are skipped);
2026-10-30 (#123), measured apart: macOS **188**, iOS simulator ("iPhone Air") **182**, the
Clipboard and haptics section's 3 included. The two together are not measured 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 @@ -55,6 +55,7 @@ The artefacts, with explicit suffixes, because sbt 2 has no `%%%`:
| `net.leibman:thicket-sqlite_3` / `_native0.5_3`, `thicket-sqlite-android_3` | SQLite through JDBC; on Native the driver comes with it, on Android add `thicket-sqlite-android` |
| `net.leibman:thicket-secrets-gtk_native0.5_3` / `thicket-secrets-android_3` | tokens and passwords in the platform's secure store (`thicket-secrets` comes with them); libsecret is optional at run time on GTK |
| `net.leibman:thicket-device-gtk_native0.5_3` / `thicket-device-android_3` | the app's lifecycle and permissions (`thicket-device` comes with them) |
| `net.leibman:thicket-device-apple_native0.5_3` | the app's lifecycle and permissions on macOS and iOS (`thicket-device` comes with it), with its own Swift library inside the jar; an iOS app adds the usage strings for what it asks |
| `net.leibman:thicket-location_3` / `_native0.5_3`, `thicket-location-android_3` | the device's position; on GTK, `Location.unavailable` from `thicket-location` |
| `net.leibman:thicket-motion_3` / `_native0.5_3`, `thicket-motion-android_3` | acceleration, rotation rate and attitude; on GTK, `Motion.unavailable` from `thicket-motion` |
| `net.leibman:thicket-clipboard-gtk_native0.5_3` / `thicket-clipboard-android_3` | text on the system clipboard (`thicket-clipboard` comes with them) |
Expand Down Expand Up @@ -170,7 +171,7 @@ shim in it.
The examples have `publish / skip := true`; the `platforms` aggregate publishes the three
renderers and the platform modules that are not in `root`: `thicket-http-apple`,
`thicket-storage-android`, `thicket-sqlite-android`, `thicket-secrets-android`,
`thicket-secrets-apple`, `thicket-device-gtk`, `thicket-device-android` and
`thicket-secrets-apple`, `thicket-device-gtk`, `thicket-device-android`, `thicket-device-apple`,
`thicket-location-android`, `thicket-motion-android`, `thicket-clipboard-gtk`,
`thicket-clipboard-android`, `thicket-clipboard-apple`, `thicket-haptics-android`,
`thicket-haptics-apple`, `thicket-pickers-gtk`, `thicket-pickers-android` and
Expand Down
8 changes: 4 additions & 4 deletions docs/16-device-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ most of them, which is why they come first.
| **Preferences** (small key–value) | `Preferences`: get/set strings, numbers, booleans | `SharedPreferences` | ~~`UserDefaults`~~ a file under the data dir, as on GTK (built, #98; `docs/decisions.md` 2026-10-22) | ~~`UserDefaults`~~ the same | a file under the data dir (GSettings needs an installed schema) |
| **Secure storage** (tokens) | `Secrets`: get/set/delete a string | Android Keystore-wrapped value | Keychain, the app's own (built, #108; the host needs keychain entitlements, on the simulator too) | Keychain (built, #108): the data-protection keychain when entitled, else the login keychain, whose items an unsigned build cannot read after a rebuild | libsecret (Secret Service), optional dependency |
| **SQLite** | plain JDBC; `Sqlite.open(name): java.sql.Connection` | Thicket's JDBC driver over `android.database.sqlite` | `scala-native-jdbc-sqlite` | same | same |
| **Lifecycle** | `AppLifecycle.state: Signal[Foreground \| Background]` and an `onTerminate` hook | **built**: `ThicketActivity`'s `onStart`/`onStop`, a rotation not counted; terminate when the last one finishes | scene notifications | `NSApplication` notifications | **built**: the window shown — mapped, not minimised or suspended — not ~~`is-active`~~, which is focus; `GApplication` shutdown |
| **Permissions** | `Permissions.request(Permission.Location)` → `Granted \| Denied \| Restricted` | **built**: `requestPermissions` + manifest; an undeclared one throws | usage strings in `Info.plist` | entitlements (sandboxed apps) | **built**: always `Granted`; xdg-desktop-portal asks for location and camera when they are used |
| **Lifecycle** | `AppLifecycle.state: Signal[Foreground \| Background]` and an `onTerminate` hook | **built**: `ThicketActivity`'s `onStart`/`onStop`, a rotation not counted; terminate when the last one finishes | **built** (#114): a scene's `willEnterForeground` to the last `didEnterBackground`; `willTerminateNotification`, which iOS rarely sends | **built** (#114): `NSApp.occlusionState` (hidden, minimised, covered, locked are background); `willTerminateNotification` | **built**: the window shown — mapped, not minimised or suspended — not ~~`is-active`~~, which is focus; `GApplication` shutdown |
| **Permissions** | `Permissions.request(Permission.Location)` → `Granted \| Denied \| Restricted` | **built**: `requestPermissions` + manifest; an undeclared one throws | **built** (#114): `AVCaptureDevice`, `UNUserNotificationCenter`; a missing usage string throws; location with #118 | **built** (#114): the same; notifications need an app bundle | **built**: always `Granted`; xdg-desktop-portal asks for location and camera when they are used |
| **Open URL, share, clipboard** | `Link` exists; add `Share.text/file`, `Clipboard.get/set` | `ACTION_SEND`, `ClipboardManager` | `UIActivityViewController`, `UIPasteboard` | `NSSharingServicePicker`, `NSPasteboard` | `GdkClipboard`; share is n/a |

**Tier 2: the hardware.**
Expand Down Expand Up @@ -313,7 +313,7 @@ this means many modules. Names follow the published ones:

| Service | API (cross: JVM, JS, Native) | Implementations |
|---|---|---|
| shared plumbing: `Availability`, `Permissions`, lifecycle, fakes | `thicket-device` (JVM, Native; `Availability` added with location) | `thicket-device-android`, `-gtk` (built); `-apple` (Mac issue) |
| shared plumbing: `Availability`, `Permissions`, lifecycle, fakes | `thicket-device` (JVM, Native; `Availability` added with location) | `thicket-device-android`, `-gtk`, `-apple` (built) |
| HTTP | none: sttp is the API | `thicket-http-apple` (#90), `thicket-http-android`, `thicket-http-gtk` |
| storage: directories, preferences | `thicket-storage` | `-android`, `-apple`, `-gtk` |
| secrets | `thicket-secrets` | `-android` (Keystore), `-apple` (Keychain), `-gtk` (libsecret) |
Expand Down Expand Up @@ -414,7 +414,7 @@ Every service gets a gallery section and self-test checks on every host where it
each item. Conformance passes 11/11 on both, and the gallery's secret goes from stored
to kept.
3. **Lifecycle and permissions:** the host plumbing every later service sits on. *Done on GTK
and Android, 2026-10-28 (`modules/device/README.md`); Apple is a Mac issue.*
and Android, 2026-10-28 (`modules/device/README.md`); on Apple 2026-10-30 (#114).*
- `ThicketActivity` and `GtkApp` tell listeners what they hear (start, stop, destruction
and permission results; shown or hidden, and shutdown). `thicket-device-android` and
`-gtk` turn that into `AppLifecycle` and `Permissions`, so an app forwards nothing.
Expand Down
Loading
Loading
0