Files
jarvis/Jarvis/JarvisApp.swift

57 lines
2.0 KiB
Swift
Raw Normal View History

// JarvisApp.swift
import SwiftUI
import SwiftData
import UIKit
import BackgroundTasks
final class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
// Register the briefing background-refresh handler before launch completes.
BGTaskScheduler.shared.register(forTaskWithIdentifier: jarvisBriefingRefreshID, using: nil) { task in
Task { @MainActor in
await NotificationManager.shared.applySettings()
NotificationManager.shared.scheduleBackgroundRefresh()
task.setTaskCompleted(success: true)
}
}
return true
}
}
@main
struct JarvisApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
@StateObject private var settings = ServerSettings.shared
@StateObject private var store = StoryStore.shared
@StateObject private var ws = WebSocketManager.shared
@StateObject private var connectivity = ConnectivitySettings.shared
@StateObject private var connManager = ConnectivityManager.shared
@StateObject private var notifications = NotificationManager.shared
var body: some Scene {
WindowGroup {
Group {
if settings.isConfigured {
RootTabView()
} else {
OnboardingView()
}
}
.environmentObject(settings)
.environmentObject(store)
.environmentObject(ws)
.environmentObject(connectivity)
.environmentObject(connManager)
.environmentObject(notifications)
.task {
connManager.start()
await connManager.resolveAndActivate()
await notifications.bootstrap()
}
}
.modelContainer(for: [CachedStory.self, CachedArticle.self, ReadStory.self, SavedStory.self])
}
}