| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- import SwiftUI
- import Swinject
- private let dependencies: [DependeciesContainer.Type] = [
- StorageContainer.self,
- ServiceContainer.self,
- APSContainer.self,
- UIContainer.self,
- NetworkContainer.self,
- SecurityContainer.self
- ]
- private extension Swinject.Resolver {
- func setup() {
- for dep in dependencies {
- dep.setup()
- }
- }
- }
- @main struct FreeAPSApp: App {
- @Environment(\.scenePhase) var scenePhase
- static let resolver = Container(defaultObjectScope: .container) { container in
- for dep in dependencies {
- dep.register(container: container)
- }
- }.synchronize()
- private static func loadServices() {
- resolver.resolve(AppearanceManager.self)!.setupGlobalAppearance()
- _ = resolver.resolve(DeviceDataManager.self)!
- _ = resolver.resolve(APSManager.self)!
- _ = resolver.resolve(FetchGlucoseManager.self)!
- _ = resolver.resolve(FetchTreatmentsManager.self)!
- _ = resolver.resolve(FetchAnnouncementsManager.self)!
- }
- init() {
- FreeAPSApp.resolver.setup()
- FreeAPSApp.loadServices()
- }
- private let mainView = Main.Builder(resolver: FreeAPSApp.resolver).buildView()
- var body: some Scene {
- WindowGroup {
- mainView
- }
- .onChange(of: scenePhase) { newScenePhase in
- switch newScenePhase {
- case .active:
- debug(.default, "APPLICATION is active")
- case .inactive:
- debug(.default, "APPLICATION is inactive")
- case .background:
- debug(.default, "APPLICATION is in background")
- @unknown default:
- debug(.default, "APPLICATION: Received an unexpected scenePhase.")
- }
- }
- }
- }
- class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
- func userNotificationCenter(
- _: UNUserNotificationCenter,
- willPresent _: UNNotification,
- withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions)
- -> Void
- ) {
- completionHandler([.banner, .badge, .sound])
- }
- func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
- // Override point for customization after application launch.
- UNUserNotificationCenter.current().delegate = self
- return true
- }
- }
|