also looking at this
feat(ios): location recording moves to the manager it always shared — ratchet 23 -> 18
#125
6 files
+1653
-170
Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.
| @@ -457,7 +457,12 @@ struct CraftWebView: UIViewRepresentable { | ||
| 457 | 457 | locationManager?.desiredAccuracy = kCLLocationAccuracyBest |
| 458 | 458 | locationManager?.activityType = .fitness |
| 459 | 459 | locationManager?.pausesLocationUpdatesAutomatically = false |
| 460 | restoreLocationRecordingState() | |
| 460 | // Zig owns the recorder when it is linked, including the | |
| 461 | // relaunch restore — see `CraftZigRuntime.adoptLocationRecording`. | |
| 462 | // Running both would leave two managers appending to one track. | |
| 463 | if !CraftZigRuntime.adoptLocationRecording() { | |
| 464 | restoreLocationRecordingState() | |
| 465 | } | |
| 461 | 466 | } |
| 462 | 467 | if config.enableContacts { |
| 463 | 468 | contactStore = CNContactStore() |
| @@ -5465,6 +5470,7 @@ final class CraftZigRuntime: NSObject { | ||
| 5465 | 5470 | private typealias HandleActionFn = @convention(c) ( |
| 5466 | 5471 | UnsafePointer<CChar>, UInt, UnsafePointer<CChar>, UInt, Int64 |
| 5467 | 5472 | ) -> Bool |
| 5473 | private typealias AdoptLocationRecordingFn = @convention(c) () -> Bool | |
| 5468 | 5474 | |
| 5469 | 5475 | private static let image: UnsafeMutableRawPointer? = dlopen(nil, RTLD_NOW) |
| 5470 | 5476 | |
| @@ -5483,6 +5489,11 @@ final class CraftZigRuntime: NSObject { | ||
| 5483 | 5489 | return unsafeBitCast(sym, to: HandleActionFn.self) |
| 5484 | 5490 | }() |
| 5485 | 5491 | |
| 5492 | private static let adoptLocationRecordingFn: AdoptLocationRecordingFn? = { | |
| 5493 | guard let sym = dlsym(image, "craft_ios_adopt_location_recording") else { return nil } | |
| 5494 | return unsafeBitCast(sym, to: AdoptLocationRecordingFn.self) | |
| 5495 | }() | |
| 5496 | ||
| 5486 | 5497 | /// Whether this build has a Zig runtime at all. Read by nothing here; kept |
| 5487 | 5498 | /// because "is Zig linked" is the first question to ask when an action |
| 5488 | 5499 | /// behaves like the Swift one after a migration was supposed to move it. |
| @@ -5497,6 +5508,24 @@ final class CraftZigRuntime: NSObject { | ||
| 5497 | 5508 | setWebViewFn?(Unmanaged.passUnretained(webView).toOpaque()) |
| 5498 | 5509 | } |
| 5499 | 5510 | |
| 5511 | /// Hand a recording that outlived the last launch to whichever runtime owns | |
| 5512 | /// the recorder. | |
| 5513 | /// | |
| 5514 | /// Returns true when Zig took it, and the caller must then *not* run | |
| 5515 | /// `restoreLocationRecordingState()`. This is the one place the usual | |
| 5516 | /// "offer it to Zig, fall back on false" pattern cannot be used through | |
| 5517 | /// `handleAction`: there is no page message at launch, and the restore | |
| 5518 | /// happens in `Coordinator.init` — before `attach`, because SwiftUI builds | |
| 5519 | /// the coordinator before the view. Whoever restores first owns the | |
| 5520 | /// `CLLocationManager` for the rest of the launch, so the decision has to | |
| 5521 | /// be made here rather than at the first `stopLocationRecording`. | |
| 5522 | /// | |
| 5523 | /// False in a build with no Zig runtime, which is exactly when Swift's own | |
| 5524 | /// restore is still the right thing to run. | |
| 5525 | static func adoptLocationRecording() -> Bool { | |
| 5526 | adoptLocationRecordingFn?() ?? false | |
| 5527 | } | |
| 5528 | ||
| 5500 | 5529 | /// Forget this webview, if Zig is still holding it. |
| 5501 | 5530 | /// |
| 5502 | 5531 | /// `attach` hands over an unretained pointer, so the moment SwiftUI |