import SwiftUI import UIKit @main struct MoltbotApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate @State private var appModel: NodeAppModel @State private var gatewayController: GatewayConnectionController @Environment(\.scenePhase) private var scenePhase init() { GatewaySettingsStore.bootstrapPersistence() let appModel = NodeAppModel() _appModel = State(initialValue: appModel) _gatewayController = State(initialValue: GatewayConnectionController(appModel: appModel)) // Register for push notifications PushManager.shared.registerForVoIPPush() Task { await PushManager.shared.registerForRemoteNotifications() } } var body: some Scene { WindowGroup { RootCanvas() .environment(self.appModel) .environment(self.appModel.voiceWake) .environment(self.gatewayController) .onOpenURL { url in Task { await self.appModel.handleDeepLink(url: url) } } .onChange(of: self.scenePhase) { _, newValue in self.appModel.setScenePhase(newValue) self.gatewayController.setScenePhase(newValue) } } } } // MARK: - AppDelegate for Push Notification Token Handling class AppDelegate: NSObject, UIApplicationDelegate { func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data ) { Task { @MainActor in PushManager.shared.didRegisterForRemoteNotifications(deviceToken: deviceToken) } } func application( _ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error ) { Task { @MainActor in PushManager.shared.didFailToRegisterForRemoteNotifications(error: error) } } }