AppMain.swift 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. import SwiftUI
  2. import Firebase
  3. // TODO: Errors are not shown to the user, but instead just logged
  4. @main
  5. struct AppMain: App {
  6. private let tag = "AppMain"
  7. @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate: AppDelegate
  8. @StateObject private var store = Store.shared
  9. init() {
  10. Log.d(tag, "Launching ntfy 🥳. Welcome!")
  11. Log.d(tag, "Base URL is \(Config.appBaseUrl), user agent is \(ApiService.userAgent)")
  12. }
  13. var body: some Scene {
  14. WindowGroup {
  15. ContentView()
  16. .environmentObject(store)
  17. .environmentObject(delegate)
  18. .environment(\.managedObjectContext, store.context)
  19. .onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in
  20. // Use this hook instead of applicationDidBecomeActive, see https://stackoverflow.com/a/68888509/1440785
  21. // That post also explains how to start SwiftUI from AppDelegate if that's ever needed.
  22. Log.d(tag, "App became active, refreshing objects")
  23. store.hardRefresh()
  24. }
  25. }
  26. }
  27. }