2026-06-18 18:04:59 +03:00
|
|
|
// JarvisApp.swift
|
|
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
import SwiftData
|
2026-06-18 22:17:41 +03:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-06-18 18:04:59 +03:00
|
|
|
|
|
|
|
|
@main
|
|
|
|
|
struct JarvisApp: App {
|
2026-06-18 22:17:41 +03:00
|
|
|
@UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
|
2026-06-18 18:04:59 +03:00
|
|
|
@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
|
2026-06-18 22:17:41 +03:00
|
|
|
@StateObject private var notifications = NotificationManager.shared
|
2026-06-18 18:04:59 +03:00
|
|
|
|
|
|
|
|
var body: some Scene {
|
|
|
|
|
WindowGroup {
|
|
|
|
|
Group {
|
|
|
|
|
if settings.isConfigured {
|
|
|
|
|
RootTabView()
|
|
|
|
|
} else {
|
|
|
|
|
OnboardingView()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.environmentObject(settings)
|
|
|
|
|
.environmentObject(store)
|
|
|
|
|
.environmentObject(ws)
|
|
|
|
|
.environmentObject(connectivity)
|
|
|
|
|
.environmentObject(connManager)
|
2026-06-18 22:17:41 +03:00
|
|
|
.environmentObject(notifications)
|
2026-06-18 18:04:59 +03:00
|
|
|
.task {
|
|
|
|
|
connManager.start()
|
|
|
|
|
await connManager.resolveAndActivate()
|
2026-06-18 22:17:41 +03:00
|
|
|
await notifications.bootstrap()
|
2026-06-18 18:04:59 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.modelContainer(for: [CachedStory.self, CachedArticle.self])
|
|
|
|
|
}
|
|
|
|
|
}
|