Make entitlement reads observable !16
7 files changed, +29 −38
Layout: unified · split
DomainDig/ContentView.swift −3
| @@ -32,7 +32,6 @@ private struct WorkflowNavigationTarget: Hashable { | ||
| 32 | 32 | struct ContentView: View { |
| 33 | 33 | @Environment(\.appDensity) private var appDensity |
| 34 | 34 | @Bindable var viewModel: DomainViewModel |
| 35 | @State private var purchaseService = PurchaseService.shared | |
| 36 | 35 | @State private var navigationPath = NavigationPath() |
| 37 | 36 | @FocusState private var focusedInputField: LookupInputField? |
| 38 | 37 | @State private var customPortInput = "" |
| @@ -48,8 +47,6 @@ struct ContentView: View { | ||
| 48 | 47 | @State private var auditStartInFlight = false |
| 49 | 48 | |
| 50 | 49 | var body: some View { |
| 51 | let _ = purchaseService.currentTier | |
| 52 | ||
| 53 | 50 | NavigationStack(path: $navigationPath) { |
| 54 | 51 | ScrollView(.vertical) { |
| 55 | 52 | VStack(spacing: 0) { |
DomainDig/DomainDigApp.swift +22 −27
| @@ -34,21 +34,7 @@ struct DomainDigApp: App { | ||
| 34 | 34 | #if DEBUG |
| 35 | 35 | viewModel.seedAuditFixturesIfRequested() |
| 36 | 36 | #endif |
| 37 | let _ = purchaseService.currentTier | |
| 38 | let _ = cloudSyncService.status | |
| 39 | let _ = localAPIService.isRunning | |
| 40 | let _ = IntegrationService.shared.targets.count | |
| 41 | await purchaseService.refreshEntitlements() | |
| 42 | viewModel.refreshMonitoringState() | |
| 43 | await viewModel.refreshMonitoringAuthorizationStatus() | |
| 44 | await cloudSyncService.refreshAvailability() | |
| 45 | localAPIService.refresh() | |
| 46 | cloudSyncService.scheduleSyncIfNeeded(trigger: .launch) | |
| 47 | viewModel.monitoringStatusMessage = DomainMonitoringScheduler.shared.syncSchedule() | |
| 48 | ScheduledReportScheduler.shared.syncSchedule() | |
| 49 | IntegrationService.shared.processQueueNow() | |
| 50 | viewModel.refreshWidgetData() | |
| 51 | consumeShareInbox() | |
| 37 | await refreshAfterBecomingActive() | |
| 52 | 38 | } |
| 53 | 39 | .onReceive(NotificationCenter.default.publisher(for: .cloudSyncDidApplyChanges)) { _ in |
| 54 | 40 | viewModel.refreshPersistedData() |
| @@ -58,21 +44,30 @@ struct DomainDigApp: App { | ||
| 58 | 44 | } |
| 59 | 45 | .onChange(of: scenePhase) { _, newValue in |
| 60 | 46 | guard newValue == .active else { return } |
| 61 | viewModel.refreshMonitoringState() | |
| 62 | Task { | |
| 63 | await viewModel.refreshMonitoringAuthorizationStatus() | |
| 64 | await cloudSyncService.refreshAvailability() | |
| 65 | } | |
| 66 | localAPIService.refresh() | |
| 67 | cloudSyncService.scheduleSyncIfNeeded(trigger: .launch) | |
| 68 | viewModel.monitoringStatusMessage = DomainMonitoringScheduler.shared.syncSchedule() | |
| 69 | ScheduledReportScheduler.shared.syncSchedule() | |
| 70 | IntegrationService.shared.processQueueNow() | |
| 71 | viewModel.refreshWidgetData() | |
| 72 | consumeShareInbox() | |
| 47 | Task { await refreshAfterBecomingActive() } | |
| 73 | 48 | } |
| 74 | 49 | } |
| 75 | 50 | |
| 51 | /// Everything that must re-run whenever the app becomes active. | |
| 52 | /// | |
| 53 | /// Launch and foreground carried near-duplicates of this, and the | |
| 54 | /// foreground copy left out `refreshEntitlements()` — so a purchase or | |
| 55 | /// cancellation made outside the app was not picked up until the next cold | |
| 56 | /// launch. | |
| 57 | private func refreshAfterBecomingActive() async { | |
| 58 | await purchaseService.refreshEntitlements() | |
| 59 | viewModel.refreshMonitoringState() | |
| 60 | await viewModel.refreshMonitoringAuthorizationStatus() | |
| 61 | await cloudSyncService.refreshAvailability() | |
| 62 | localAPIService.refresh() | |
| 63 | cloudSyncService.scheduleSyncIfNeeded(trigger: .launch) | |
| 64 | viewModel.monitoringStatusMessage = DomainMonitoringScheduler.shared.syncSchedule() | |
| 65 | ScheduledReportScheduler.shared.syncSchedule() | |
| 66 | IntegrationService.shared.processQueueNow() | |
| 67 | viewModel.refreshWidgetData() | |
| 68 | consumeShareInbox() | |
| 69 | } | |
| 70 | ||
| 76 | 71 | /// Picks up a domain shared via the share extension and routes it into an |
| 77 | 72 | /// inspection through the intent router (consumed by `RootTabView`). |
| 78 | 73 | private func consumeShareInbox() { |
DomainDig/FeatureAccessService.swift +7 −1
| @@ -85,8 +85,14 @@ struct UpgradePromptContext: Identifiable, Equatable { | ||
| 85 | 85 | enum FeatureAccessService { |
| 86 | 86 | private static let effectivelyUnlimitedTrackedDomains = 5_000 |
| 87 | 87 | |
| 88 | /// Reads the observable property rather than `PurchaseService.cachedTier`, | |
| 89 | /// the static over UserDefaults. SwiftUI records a dependency for any | |
| 90 | /// observable property read while a body evaluates, however deep in the | |
| 91 | /// call tree, so every `hasAccess` call site in a view now updates when a | |
| 92 | /// purchase lands. The nine `let _ = purchaseService.currentTier` discards | |
| 93 | /// that used to manufacture that dependency are gone with this. | |
| 88 | 94 | static var currentTier: FeatureTier { |
| 89 | PurchaseService.cachedTier | |
| 95 | PurchaseService.shared.currentTier | |
| 90 | 96 | } |
| 91 | 97 | |
| 92 | 98 | static var entitlements: FeatureEntitlements { |
DomainDig/RootTabView.swift −2
| @@ -37,8 +37,6 @@ struct RootTabView: View { | ||
| 37 | 37 | @State private var selectedTab: RootTab = FeatureAccessService.currentTier == .free ? .inspect : .dashboard |
| 38 | 38 | |
| 39 | 39 | var body: some View { |
| 40 | let _ = purchaseService.currentTier | |
| 41 | ||
| 42 | 40 | Group { |
| 43 | 41 | if horizontalSizeClass == .regular { |
| 44 | 42 | splitLayout |
DomainDig/SettingsViews.swift −1
| @@ -11,7 +11,6 @@ struct SettingsView: View { | ||
| 11 | 11 | @State private var purchaseService = PurchaseService.shared |
| 12 | 12 | |
| 13 | 13 | var body: some View { |
| 14 | let _ = purchaseService.currentTier | |
| 15 | 14 | |
| 16 | 15 | List { |
| 17 | 16 | Section("Tier") { |
DomainDig/WatchlistView.swift −2
| @@ -5,7 +5,6 @@ struct WatchlistView: View { | ||
| 5 | 5 | @Environment(\.accessibilityReduceMotion) private var reduceMotion |
| 6 | 6 | @Bindable var viewModel: DomainViewModel |
| 7 | 7 | @Environment(\.dismiss) private var dismiss |
| 8 | @State private var purchaseService = PurchaseService.shared | |
| 9 | 8 | @State private var showWorkflowAddSheet = false |
| 10 | 9 | @State private var showAddDomainSheet = false |
| 11 | 10 | @State private var newTrackedDomain = "" |
| @@ -24,7 +23,6 @@ struct WatchlistView: View { | ||
| 24 | 23 | } |
| 25 | 24 | |
| 26 | 25 | var body: some View { |
| 27 | let _ = purchaseService.currentTier | |
| 28 | 26 | |
| 29 | 27 | List { |
| 30 | 28 | if !viewModel.allWatchlistTags.isEmpty { |
DomainDig/WorkflowsView.swift −2
| @@ -10,12 +10,10 @@ private enum WorkflowDestinationMode: String, CaseIterable, Identifiable { | ||
| 10 | 10 | struct WorkflowsView: View { |
| 11 | 11 | @Environment(\.appDensity) private var appDensity |
| 12 | 12 | @Bindable var viewModel: DomainViewModel |
| 13 | @State private var purchaseService = PurchaseService.shared | |
| 14 | 13 | |
| 15 | 14 | @State private var showingCreateWorkflow = false |
| 16 | 15 | |
| 17 | 16 | var body: some View { |
| 18 | let _ = purchaseService.currentTier | |
| 19 | 17 | |
| 20 | 18 | List { |
| 21 | 19 | if let limitMessage = FeatureAccessService.workflowAllowanceSummary(currentCount: viewModel.workflows.count) { |