Parcourir la source

Fix duplicate paywall dismiss after purchase or restore.

Rely on premiumStatusDidChange as the single path to dismiss the paywall when entitlements update.

Co-authored-by: Cursor <cursoragent@cursor.com>
AhtashamShahzad1 il y a 4 semaines
Parent
commit
d77ee46d84
2 fichiers modifiés avec 1 ajouts et 13 suppressions
  1. 1 10
      smart_printer/PaywallView.swift
  2. 0 3
      smart_printer/ViewController.swift

+ 1 - 10
smart_printer/PaywallView.swift

@@ -1028,7 +1028,6 @@ private final class PaywallCTAButton: NSButton, AppearanceRefreshable {
 
 final class PaywallView: NSView, AppearanceRefreshable {
     var onClose: (() -> Void)?
-    var onPurchaseSucceeded: (() -> Void)?
 
     private var selectedPlan: PaywallPlan = .yearly
     private var planCards: [PaywallPlan: PaywallPlanCard] = [:]
@@ -1516,7 +1515,6 @@ final class PaywallView: NSView, AppearanceRefreshable {
                 let succeeded = try await StoreManager.shared.purchase(plan: selectedPlan)
                 refreshStoreState()
                 if succeeded {
-                    onPurchaseSucceeded?()
                     AppRatingManager.shared.promptAfterFirstPurchaseIfNeeded(on: window)
                 }
             } catch {
@@ -1532,9 +1530,7 @@ final class PaywallView: NSView, AppearanceRefreshable {
             do {
                 let restored = try await StoreManager.shared.restorePurchases()
                 refreshStoreState()
-                if restored {
-                    onPurchaseSucceeded?()
-                } else {
+                if !restored {
                     StoreManager.shared.showAlert(
                         title: "No Purchases Found",
                         message: "We couldn't find any previous purchases for this Apple ID.",
@@ -1582,7 +1578,6 @@ final class PaywallView: NSView, AppearanceRefreshable {
 
 final class PaywallOverlayView: NSView, AppearanceRefreshable {
     var onDismiss: (() -> Void)?
-    var onPurchaseSucceeded: (() -> Void)?
 
     private let paywallView: PaywallView
     private let blurView = NSVisualEffectView()
@@ -1626,10 +1621,6 @@ final class PaywallOverlayView: NSView, AppearanceRefreshable {
 
         paywallView.translatesAutoresizingMaskIntoConstraints = false
         paywallView.onClose = { [weak self] in self?.dismiss() }
-        paywallView.onPurchaseSucceeded = { [weak self] in
-            self?.paywallView.refreshStoreState()
-            self?.onPurchaseSucceeded?()
-        }
 
         addSubview(blurView)
         addSubview(backdrop)

+ 0 - 3
smart_printer/ViewController.swift

@@ -498,9 +498,6 @@ class ViewController: NSViewController {
                 self.showDestination(.home)
             }
         }
-        overlay.onPurchaseSucceeded = { [weak self] in
-            self?.navigateHomeAfterPremiumUnlock()
-        }
         overlay.present(in: view)
         paywallOverlay = overlay
     }