Ver código fonte

Auto-show launch paywall and prompt for lifetime upgrades

Show paywall 2s after launch for non-premium users, default paywall selection to Lifetime for premium users, and alert users to cancel existing subscriptions after upgrading to Lifetime.

Co-authored-by: Cursor <cursoragent@cursor.com>
huzaifahayat12 2 meses atrás
pai
commit
f82fb0a5e0
1 arquivos alterados com 48 adições e 1 exclusões
  1. 48 1
      zoom_app/ViewController.swift

+ 48 - 1
zoom_app/ViewController.swift

@@ -512,6 +512,9 @@ class ViewController: NSViewController {
 
     private let storeKitCoordinator = StoreKitCoordinator()
     private var storeKitStartupTask: Task<Void, Never>?
+    private var launchPaywallWorkItem: DispatchWorkItem?
+    private let launchPaywallDelay: TimeInterval = 2
+    private var hasPresentedLaunchPaywall = false
 
     override func viewDidLoad() {
         super.viewDidLoad()
@@ -541,6 +544,7 @@ class ViewController: NSViewController {
         alignNativeTrafficLights()
         showHomeView(profile: nil)
         syncBrandPositionForCurrentWindowState(animated: false)
+        scheduleLaunchPaywallIfNeeded()
     }
 
     override func viewDidLayout() {
@@ -3386,16 +3390,47 @@ class ViewController: NSViewController {
                     self.premiumRatingPromptWorkItem = nil
                     self.showPaywall()
                 }
+                if newIsPremium {
+                    self.launchPaywallWorkItem?.cancel()
+                    self.launchPaywallWorkItem = nil
+                    self.hasPresentedLaunchPaywall = true
+                } else {
+                    self.scheduleLaunchPaywallIfNeeded()
+                }
             }
         }
         storeKitStartupTask = Task { [weak self] in
             await self?.storeKitCoordinator.start()
             await MainActor.run {
                 self?.updatePremiumButtons()
+                self?.scheduleLaunchPaywallIfNeeded()
             }
         }
     }
 
+    private func scheduleLaunchPaywallIfNeeded() {
+        guard hasPresentedLaunchPaywall == false else { return }
+        guard storeKitCoordinator.hasPremiumAccess == false else {
+            hasPresentedLaunchPaywall = true
+            return
+        }
+        guard launchPaywallWorkItem == nil else { return }
+
+        let workItem = DispatchWorkItem { [weak self] in
+            guard let self else { return }
+            self.launchPaywallWorkItem = nil
+            guard self.hasPresentedLaunchPaywall == false else { return }
+            guard self.storeKitCoordinator.hasPremiumAccess == false else {
+                self.hasPresentedLaunchPaywall = true
+                return
+            }
+            self.hasPresentedLaunchPaywall = true
+            self.showPaywall()
+        }
+        launchPaywallWorkItem = workItem
+        DispatchQueue.main.asyncAfter(deadline: .now() + launchPaywallDelay, execute: workItem)
+    }
+
     @MainActor
     private func updatePremiumButtons() {
         let isPremium = storeKitCoordinator.hasPremiumAccess
@@ -3497,6 +3532,9 @@ class ViewController: NSViewController {
     // MARK: - Paywall (ported from meetings_app)
 
     private func showPaywall() {
+        if storeKitCoordinator.hasPremiumAccess && storeKitCoordinator.hasLifetimePremiumAccess == false {
+            selectedPremiumPlan = .lifetime
+        }
         if let existing = paywallOverlayView {
             refreshPaywallStoreUI()
             if let superview = existing.superview {
@@ -4495,6 +4533,8 @@ class ViewController: NSViewController {
         paywallPurchaseTask?.cancel()
         updatePaywallContinueState(isLoading: true)
         let selectedPlan = selectedPremiumPlan
+        let hadPremiumBeforePurchase = storeKitCoordinator.hasPremiumAccess
+        let hadLifetimeBeforePurchase = storeKitCoordinator.hasLifetimePremiumAccess
         paywallPurchaseTask = Task { [weak self] in
             guard let self else { return }
             if self.storeKitCoordinator.productsByID[selectedPlan.rawValue] == nil {
@@ -4513,7 +4553,14 @@ class ViewController: NSViewController {
                         UserDefaults.standard.set(false, forKey: self.ratingPromptShownKey)
                         self.schedulePremiumRatingPromptIfNeeded()
                     }
-                    self.showSimpleAlert(title: "Purchase Complete", message: "Premium has been unlocked successfully.")
+                    if selectedPlan == .lifetime, hadLifetimeBeforePurchase == false, hadPremiumBeforePurchase {
+                        self.showSimpleAlert(
+                            title: "Lifetime Activated",
+                            message: "Lifetime premium is now active. If you previously subscribed (weekly/monthly/yearly), please cancel that subscription in your Apple ID subscriptions to avoid future renewals."
+                        )
+                    } else {
+                        self.showSimpleAlert(title: "Purchase Complete", message: "Premium has been unlocked successfully.")
+                    }
                     self.hidePaywall()
                     if self.storeKitCoordinator.hasPremiumAccess {
                         DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) { [weak self] in