RootView.swift 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import SwiftUI
  2. struct RootView: View {
  3. @EnvironmentObject private var subscriptions: SubscriptionManager
  4. let session: AppSessionState
  5. @Bindable var splashViewModel: SplashViewModel
  6. var body: some View {
  7. ZStack {
  8. FrontPageView(session: session)
  9. if splashViewModel.isVisible {
  10. SplashScreenView(viewModel: splashViewModel)
  11. .transition(.opacity)
  12. .zIndex(1)
  13. }
  14. }
  15. .animation(.easeInOut(duration: 0.45), value: splashViewModel.isVisible)
  16. .task {
  17. async let splash: Void = splashViewModel.runIfNeeded()
  18. async let entitlements: Void = subscriptions.ensureEntitlementsResolved()
  19. _ = await (splash, entitlements)
  20. syncToolSubscriptionState()
  21. }
  22. }
  23. private func syncToolSubscriptionState() {
  24. let hasPremium = subscriptions.hasPremiumAccess
  25. let hasEverPurchased = subscriptions.hasEverPurchasedPremium
  26. session.postGenerator.setSubscriptionState(
  27. hasPremiumAccess: hasPremium,
  28. hasEverPurchasedPremium: hasEverPurchased
  29. )
  30. session.titleOptimizer.setSubscriptionState(
  31. hasPremiumAccess: hasPremium,
  32. hasEverPurchasedPremium: hasEverPurchased
  33. )
  34. session.commentWriter.setSubscriptionState(
  35. hasPremiumAccess: hasPremium,
  36. hasEverPurchasedPremium: hasEverPurchased
  37. )
  38. }
  39. }