Procházet zdrojové kódy

Show premium paywall on startup for non-premium users.

Schedule a 5-second delayed paywall check after launch, refresh entitlements before presenting, and cancel the startup task when the root view disappears.

Made-with: Cursor
huzaifahayat12 před 3 měsíci
rodič
revize
6887748ee8
1 změnil soubory, kde provedl 15 přidání a 0 odebrání
  1. 15 0
      google_apps/LauncherRootView.swift

+ 15 - 0
google_apps/LauncherRootView.swift

@@ -16,6 +16,7 @@ struct LauncherRootView: View {
     @State private var showingManageSubscriptionSheet = false
     @State private var showingCreateAppSheet = false
     @State private var previouslyPremiumUnlocked = false
+    @State private var startupPaywallTask: Task<Void, Never>?
     @State private var customApps: [LauncherApp] = []
     @State private var appOrder: [UUID] = []
     @State private var draggedAppID: UUID?
@@ -197,6 +198,20 @@ struct LauncherRootView: View {
                     selectedAppID: id
                 )
             }
+
+            startupPaywallTask?.cancel()
+            startupPaywallTask = Task {
+                try? await Task.sleep(nanoseconds: 5_000_000_000)
+                guard !Task.isCancelled else { return }
+                await premiumStore.refreshEntitlements()
+                guard !premiumStore.isPremiumUnlocked else { return }
+                guard !showingPremiumScreen else { return }
+                showingPremiumScreen = true
+            }
+        }
+        .onDisappear {
+            startupPaywallTask?.cancel()
+            startupPaywallTask = nil
         }
     }