Last active
February 4, 2026 05:29
-
-
Save timboudreau/136a63381380d3046fca4c89b7d343ec to your computer and use it in GitHub Desktop.
nonisolated and isolated in AppDelegate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fileprivate final class MixenAppDelegate: NSObject, UIApplicationDelegate, MXMetricManagerSubscriber { | |
| nonisolated let registered = AtomicBool() | |
| func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { | |
| // Get this out of the critial path of startup, or we will get passed metrics packets to | |
| // process before the main UI is on-screen | |
| if OnboardingState.initial.isReadyForUse { | |
| DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + 75) { | |
| self.register() | |
| } | |
| } | |
| let configuration = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role) | |
| configuration.delegateClass = MixenSceneDelegate.self | |
| return configuration | |
| } | |
| nonisolated func register() { | |
| if registered.exchange(true) { | |
| MXMetricManager.shared.add(self) | |
| Logger.metrics.notice("Registered to collect metrics") | |
| } | |
| } | |
| func applicationWillTerminate(_ application: UIApplication) { | |
| MXMetricManager.shared.remove(self) | |
| } | |
| nonisolated func didReceive(_ payloads: [MXMetricPayload]) { | |
| for payload in payloads { | |
| Logger.misc.debug("Received metrics: \(payload.jsonRepresentation())") | |
| if let mmx = MixenMetrics2(payload) { | |
| mmx.send() | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment