Selaa lähdekoodia

Update status menu visibility for premium meetings

Show top meetings only when the user is signed in with premium access, and refresh status bar state immediately on auth and entitlement changes.

Made-with: Cursor
huzaifahayat12 1 kuukausi sitten
vanhempi
commit
7118d8ce30

+ 11 - 1
meetings_app/StatusBar/StatusBarController.swift

@@ -5,6 +5,7 @@ final class StatusBarController: NSObject {
5 5
     private let authService = GoogleOAuthService.shared
6 6
     private let statusItem: NSStatusItem
7 7
     private var observers: [NSObjectProtocol] = []
8
+    private var hasPremiumAccess = false
8 9
 
9 10
     override init() {
10 11
         statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
@@ -29,6 +30,13 @@ final class StatusBarController: NSObject {
29 30
         observers.append(center.addObserver(forName: .widgetSignInRequested, object: nil, queue: .main) { [weak self] _ in
30 31
             self?.rebuildMenu()
31 32
         })
33
+        observers.append(center.addObserver(forName: .statusBarPremiumAccessChanged, object: nil, queue: .main) { [weak self] notification in
34
+            guard let self else { return }
35
+            if let hasPremium = notification.userInfo?["hasPremiumAccess"] as? Bool {
36
+                self.hasPremiumAccess = hasPremium
37
+            }
38
+            self.rebuildMenu()
39
+        })
32 40
     }
33 41
 
34 42
     deinit {
@@ -50,7 +58,7 @@ final class StatusBarController: NSObject {
50 58
         addOpenSidebarItem(title: "Settings", pageRaw: 4, to: menu)
51 59
 
52 60
         let signedIn = authService.loadTokens() != nil
53
-        if signedIn {
61
+        if signedIn && hasPremiumAccess {
54 62
             let topMeetings = WidgetMeetingStore.load().prefix(3).map { $0 }
55 63
             menu.addItem(.separator())
56 64
             let header = NSMenuItem(title: "Top meetings", action: nil, keyEquivalent: "")
@@ -71,7 +79,9 @@ final class StatusBarController: NSObject {
71 79
                     menu.addItem(item)
72 80
                 }
73 81
             }
82
+        }
74 83
 
84
+        if signedIn {
75 85
             menu.addItem(.separator())
76 86
             let signOutItem = NSMenuItem(title: "Sign Out", action: #selector(signOutClicked), keyEquivalent: "")
77 87
             signOutItem.target = self

+ 10 - 0
meetings_app/ViewController.swift

@@ -445,6 +445,11 @@ final class ViewController: NSViewController {
445 445
             guard let self else { return }
446 446
             self.handlePremiumAccessChanged(hasPremiumAccess)
447 447
         }
448
+        NotificationCenter.default.post(
449
+            name: .statusBarPremiumAccessChanged,
450
+            object: nil,
451
+            userInfo: ["hasPremiumAccess": storeKitCoordinator.hasPremiumAccess]
452
+        )
448 453
         migrateLegacyRatingStateIfNeeded()
449 454
         beginUsageTrackingSessionIfNeeded()
450 455
         observeAppLifecycleForUsageTrackingIfNeeded()
@@ -1564,6 +1569,11 @@ private extension ViewController {
1564 1569
     private func handlePremiumAccessChanged(_ hasPremiumAccess: Bool) {
1565 1570
         let hadPremiumAccess = lastKnownPremiumAccess
1566 1571
         lastKnownPremiumAccess = hasPremiumAccess
1572
+        NotificationCenter.default.post(
1573
+            name: .statusBarPremiumAccessChanged,
1574
+            object: nil,
1575
+            userInfo: ["hasPremiumAccess": hasPremiumAccess]
1576
+        )
1567 1577
         premiumUpgradeRatingPromptWorkItem?.cancel()
1568 1578
         refreshPaywallStoreUI()
1569 1579
         refreshScheduleCardsForPremiumStateChange()

+ 1 - 0
meetings_app/Widgets/DesktopWidgetView.swift

@@ -359,6 +359,7 @@ extension Notification.Name {
359 359
     static let widgetRefreshRequested = Notification.Name("widgetRefreshRequested")
360 360
     static let widgetOpenMeetingLinkRequested = Notification.Name("widgetOpenMeetingLinkRequested")
361 361
     static let statusBarOpenSidebarPage = Notification.Name("statusBarOpenSidebarPage")
362
+    static let statusBarPremiumAccessChanged = Notification.Name("statusBarPremiumAccessChanged")
362 363
     static let statusBarSignOutRequested = Notification.Name("statusBarSignOutRequested")
363 364
     static let meetingsSnapshotUpdated = Notification.Name("meetingsSnapshotUpdated")
364 365
 }