|
|
@@ -133,6 +133,7 @@ private final class PremiumPlansViewController: NSViewController {
|
|
133
|
133
|
private let subscriptionStore = SubscriptionStore.shared
|
|
134
|
134
|
private var planPriceFields: [String: (price: NSTextField, period: NSTextField)] = [:]
|
|
135
|
135
|
private var planPurchaseButtons: [String: NSButton] = [:]
|
|
|
136
|
+ private var subscriptionPrimaryFooterButton: NSButton?
|
|
136
|
137
|
private var subscriptionStatusObservation: NSObjectProtocol?
|
|
137
|
138
|
|
|
138
|
139
|
private let plans: [Plan] = [
|
|
|
@@ -213,6 +214,7 @@ private final class PremiumPlansViewController: NSViewController {
|
|
213
|
214
|
Task { @MainActor in
|
|
214
|
215
|
await self?.subscriptionStore.loadProducts()
|
|
215
|
216
|
self?.applyStorePricing()
|
|
|
217
|
+ self?.updateSubscriptionPrimaryFooter()
|
|
216
|
218
|
}
|
|
217
|
219
|
}
|
|
218
|
220
|
Task { await loadStoreProducts() }
|
|
|
@@ -506,17 +508,23 @@ private final class PremiumPlansViewController: NSViewController {
|
|
506
|
508
|
}
|
|
507
|
509
|
|
|
508
|
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
|
518
|
let entries: [(text: String, action: Selector?)] = [
|
|
510
|
|
- ("Manage Subscription", #selector(didTapManageSubscription)),
|
|
511
|
519
|
("Restore Purchase", #selector(didTapRestorePurchases)),
|
|
512
|
520
|
("Privacy Policy", nil),
|
|
513
|
521
|
("Terms of Services", nil),
|
|
514
|
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
|
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
|
529
|
return footerCell(text: entry.text, showsTrailingDivider: index < entries.count - 1)
|
|
522
|
530
|
}
|
|
|
@@ -530,7 +538,7 @@ private final class PremiumPlansViewController: NSViewController {
|
|
530
|
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
|
542
|
let container = NSView()
|
|
535
|
543
|
container.translatesAutoresizingMaskIntoConstraints = false
|
|
536
|
544
|
|
|
|
@@ -558,7 +566,15 @@ private final class PremiumPlansViewController: NSViewController {
|
|
558
|
566
|
}
|
|
559
|
567
|
|
|
560
|
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
|
580
|
private func footerCell(text: String, showsTrailingDivider: Bool) -> NSView {
|
|
|
@@ -639,9 +655,13 @@ private final class PremiumPlansViewController: NSViewController {
|
|
639
|
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
|
667
|
@objc private func didTapRestorePurchases() {
|