Explorar o código

Premium footer: show Continue with free plan when not subscribed

Replace Manage Subscription for non-Pro users, refresh label on
subscription status changes, and dismiss the sheet when choosing free.

Co-authored-by: Cursor <cursoragent@cursor.com>
AhtashamShahzad1 hai 3 semanas
pai
achega
cc092d3cfc

+ 28 - 8
App for Indeed/Controllers/PremiumPlansWindowController.swift

@@ -133,6 +133,7 @@ private final class PremiumPlansViewController: NSViewController {
133
     private let subscriptionStore = SubscriptionStore.shared
133
     private let subscriptionStore = SubscriptionStore.shared
134
     private var planPriceFields: [String: (price: NSTextField, period: NSTextField)] = [:]
134
     private var planPriceFields: [String: (price: NSTextField, period: NSTextField)] = [:]
135
     private var planPurchaseButtons: [String: NSButton] = [:]
135
     private var planPurchaseButtons: [String: NSButton] = [:]
136
+    private var subscriptionPrimaryFooterButton: NSButton?
136
     private var subscriptionStatusObservation: NSObjectProtocol?
137
     private var subscriptionStatusObservation: NSObjectProtocol?
137
 
138
 
138
     private let plans: [Plan] = [
139
     private let plans: [Plan] = [
@@ -213,6 +214,7 @@ private final class PremiumPlansViewController: NSViewController {
213
             Task { @MainActor in
214
             Task { @MainActor in
214
                 await self?.subscriptionStore.loadProducts()
215
                 await self?.subscriptionStore.loadProducts()
215
                 self?.applyStorePricing()
216
                 self?.applyStorePricing()
217
+                self?.updateSubscriptionPrimaryFooter()
216
             }
218
             }
217
         }
219
         }
218
         Task { await loadStoreProducts() }
220
         Task { await loadStoreProducts() }
@@ -506,17 +508,23 @@ private final class PremiumPlansViewController: NSViewController {
506
     }
508
     }
507
 
509
 
508
     private func makeFooterRow() -> NSView {
510
     private func makeFooterRow() -> NSView {
511
+        let primary = footerActionCell(
512
+            title: subscriptionPrimaryFooterTitle(),
513
+            action: #selector(didTapPrimaryFooterSubscriptionAction),
514
+            showsTrailingDivider: true
515
+        )
516
+        subscriptionPrimaryFooterButton = primary.button
517
+
509
         let entries: [(text: String, action: Selector?)] = [
518
         let entries: [(text: String, action: Selector?)] = [
510
-            ("Manage Subscription", #selector(didTapManageSubscription)),
511
             ("Restore Purchase", #selector(didTapRestorePurchases)),
519
             ("Restore Purchase", #selector(didTapRestorePurchases)),
512
             ("Privacy Policy", nil),
520
             ("Privacy Policy", nil),
513
             ("Terms of Services", nil),
521
             ("Terms of Services", nil),
514
             ("Support", nil)
522
             ("Support", nil)
515
         ]
523
         ]
516
 
524
 
517
-        let cells = entries.enumerated().map { index, entry in
525
+        let cells = [primary.container] + entries.enumerated().map { index, entry in
518
             if let action = entry.action {
526
             if let action = entry.action {
519
-                return footerActionCell(title: entry.text, action: action, showsTrailingDivider: index < entries.count - 1)
527
+                return footerActionCell(title: entry.text, action: action, showsTrailingDivider: index < entries.count - 1).container
520
             }
528
             }
521
             return footerCell(text: entry.text, showsTrailingDivider: index < entries.count - 1)
529
             return footerCell(text: entry.text, showsTrailingDivider: index < entries.count - 1)
522
         }
530
         }
@@ -530,7 +538,7 @@ private final class PremiumPlansViewController: NSViewController {
530
         return links
538
         return links
531
     }
539
     }
532
 
540
 
533
-    private func footerActionCell(title: String, action: Selector, showsTrailingDivider: Bool) -> NSView {
541
+    private func footerActionCell(title: String, action: Selector, showsTrailingDivider: Bool) -> (container: NSView, button: NSButton) {
534
         let container = NSView()
542
         let container = NSView()
535
         container.translatesAutoresizingMaskIntoConstraints = false
543
         container.translatesAutoresizingMaskIntoConstraints = false
536
 
544
 
@@ -558,7 +566,15 @@ private final class PremiumPlansViewController: NSViewController {
558
         }
566
         }
559
 
567
 
560
         NSLayoutConstraint.activate(constraints)
568
         NSLayoutConstraint.activate(constraints)
561
-        return container
569
+        return (container, button)
570
+    }
571
+
572
+    private func subscriptionPrimaryFooterTitle() -> String {
573
+        subscriptionStore.isProActive ? "Manage Subscription" : "Continue with free plan"
574
+    }
575
+
576
+    private func updateSubscriptionPrimaryFooter() {
577
+        subscriptionPrimaryFooterButton?.title = subscriptionPrimaryFooterTitle()
562
     }
578
     }
563
 
579
 
564
     private func footerCell(text: String, showsTrailingDivider: Bool) -> NSView {
580
     private func footerCell(text: String, showsTrailingDivider: Bool) -> NSView {
@@ -639,9 +655,13 @@ private final class PremiumPlansViewController: NSViewController {
639
         Task { await purchasePlan(planKey: planKey) }
655
         Task { await purchasePlan(planKey: planKey) }
640
     }
656
     }
641
 
657
 
642
-    @objc private func didTapManageSubscription() {
643
-        guard let url = URL(string: "https://apps.apple.com/account/subscriptions") else { return }
644
-        NSWorkspace.shared.open(url)
658
+    @objc private func didTapPrimaryFooterSubscriptionAction() {
659
+        if subscriptionStore.isProActive {
660
+            guard let url = URL(string: "https://apps.apple.com/account/subscriptions") else { return }
661
+            NSWorkspace.shared.open(url)
662
+        } else {
663
+            didTapClose()
664
+        }
645
     }
665
     }
646
 
666
 
647
     @objc private func didTapRestorePurchases() {
667
     @objc private func didTapRestorePurchases() {