Skip to content

Migrate platform channels to Pigeon 29 - #347

Closed
fotiDim wants to merge 5 commits into
mainfrom
migrate-pigeon-29
Closed

fotiDim wants to merge 5 commits into
mainfrom
migrate-pigeon-29

Conversation

@fotiDim

@fotiDim fotiDim commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Regenerates the Pigeon outputs with 29.0.10 (from 26.3.4). Pigeon 29 changes the generated channel shape, not just formatting: the Kotlin channel methods become suspend and the Swift ones become async throws, so the hand-written plugins had to be adapted.

Changes

  • Generated: all five Pigeon outputs regenerated to v29.0.10 (lib/src/universal_ble.g.dart, UniversalBle.g.kt, UniversalBle.g.swift, windows/.../universal_ble.g.{h,cpp}), Dart file formatted.
  • Android: bridge the previous callback implementations to the new suspend interface (suspendCancellableCoroutine), deliver Dart callbacks from coroutines on the main dispatcher, and add kotlinx-coroutines-android. Peripheral read/write requests await the Dart reply and respond from a coroutine.
  • Darwin: bridge the completion-based implementations to the new async protocol (withCheckedThrowingContinuation), deliver Dart callbacks via Task { @MainActor in ... }, and answer peripheral read/write requests asynchronously (no semaphores, to avoid a main-actor deadlock).
  • Windows: generated additions only (operator<<, PigeonInternalToString); the abstract interfaces are unchanged, so no hand-written changes were needed.
  • Tests: MtuCompletionTest and DisconnectCloseTest adapted to the suspend API; kotlinx-coroutines-test added to provide a Main dispatcher on the JVM.
  • Changelog: the 3.1.1 entry now describes the regeneration instead of "bump dev dependency".

No change to the public Dart API; still 3.1.1.

Verification

  • cd example/android && gradle :universal_ble:testDebugUnitTest — passed (51 tests)
  • flutter build macos --debug — built
  • flutter analyze — no issues
  • flutter test — passed (285 tests)

Notes

  • Windows was not built locally (no Windows toolchain); its generated interface is unchanged and CI covers flutter build windows + ctest.
  • The bulk of the diff is generated code. The hand-written changes are UniversalBlePlugin.{kt,swift}, UniversalBlePeripheralPlugin.{kt,swift}, the two Android tests, and android/build.gradle.

Regenerate the Pigeon outputs with 29.0.10 (from 26.3.4). The generated Kotlin and Swift channels are now coroutine/async based, so the native plugins had to be adapted:

- Android: bridge the previous callback implementations to the new suspend interface, deliver Dart callbacks from coroutines, and depend on kotlinx-coroutines-android.
- Darwin: bridge the completion-based implementations to the new async protocol, deliver Dart callbacks with @mainactor Tasks, and answer peripheral read/write requests asynchronously.
- Windows: only generated helpers (operator<<, PigeonInternalToString) were added; the abstract interfaces are unchanged, so no hand-written changes were needed.
- Tests: adapt MtuCompletionTest and DisconnectCloseTest to the suspend API and provide a Main dispatcher on the JVM.

No change to the public Dart API.
- Share one fire-and-forget helper per platform (Kotlin `fireAndForget`, Swift `DartCallbackSender.sendToDart`) instead of duplicated per-plugin helpers, and log delivery failures instead of swallowing them.
- Bound peripheral read/write requests so a dropped Dart reply cannot pin the CoreBluetooth/GATT request open (10s), then answer the central with a failure.
- Add a shared `MainDispatcherTest` base for JVM tests that deliver through Dispatchers.Main.
- Add a CI job that regenerates the Pigeon outputs and fails if they drift from the pinned version.
…al indirection

- Darwin: the pending-request registries (`…Future`, availability/permission handlers) now hold `CheckedContinuation` instead of completion closures. The generated async protocol methods are the single entry point; the old `…Impl` methods are gone (the continuation-taking logic is now an overload of the same name). Added a `CheckedContinuation.finish(_:)` helper to avoid the Swift 6 `Error`/`any Error` ambiguity of `resume(with:)`.
- Android: keep the callback-driven GATT logic but remove the `…Internal` naming noise (same-name overloads taking a `(Result<T>) -> Unit`), matching Darwin.
- Cancellation wiring is intentionally not part of this change (it needs thread-safe pending-request removal and its own tests).
Note the two pieces intentionally left out of the migration: coroutine/async cancellation wiring (both platforms) and converting the Android pending-request registries to CancellableContinuation as done on Darwin.
…ridging

The Pigeon 29 migration converted the iOS-only AccessorySetupKit picker to
CheckedContinuation but left several references in the old closure shape,
so the iOS target did not compile:

- pickerCompletion now stores the continuation instead of a closure
- showPicker assigns the continuation parameter (not the removed completion)
- completePicker resumes the stored continuation
- requestDevice/unPair pass continuation: instead of a trailing closure

Also:
- capture the advertising state locally before deferred Dart delivery so a
  later state change cannot alter the value sent to Dart
- stop swallowing genuine CancellationException in the Android peripheral
  awaitReply timeout bridge
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.

1 participant