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 | struct ContentView: View { | 32 | struct ContentView: View { |
| 33 | @Environment(\.appDensity) private var appDensity | 33 | @Environment(\.appDensity) private var appDensity |
| 34 | @Bindable var viewModel: DomainViewModel | 34 | @Bindable var viewModel: DomainViewModel |
| 35 | @State private var purchaseService = PurchaseService.shared | ||
| 36 | @State private var navigationPath = NavigationPath() | 35 | @State private var navigationPath = NavigationPath() |
| 37 | @FocusState private var focusedInputField: LookupInputField? | 36 | @FocusState private var focusedInputField: LookupInputField? |
| 38 | @State private var customPortInput = "" | 37 | @State private var customPortInput = "" |
| @@ -48,8 +47,6 @@ struct ContentView: View { | |||
| 48 | @State private var auditStartInFlight = false | 47 | @State private var auditStartInFlight = false |
| 49 | 48 | ||
| 50 | var body: some View { | 49 | var body: some View { |
| 51 | let _ = purchaseService.currentTier | ||
| 52 | |||
| 53 | NavigationStack(path: $navigationPath) { | 50 | NavigationStack(path: $navigationPath) { |
| 54 | ScrollView(.vertical) { | 51 | ScrollView(.vertical) { |
| 55 | VStack(spacing: 0) { | 52 | VStack(spacing: 0) { |
DomainDig/DomainDigApp.swift +22 −27
| @@ -34,21 +34,7 @@ struct DomainDigApp: App { | |||
| 34 | #if DEBUG | 34 | #if DEBUG |
| 35 | viewModel.seedAuditFixturesIfRequested() | 35 | viewModel.seedAuditFixturesIfRequested() |
| 36 | #endif | 36 | #endif |
| 37 | let _ = purchaseService.currentTier | 37 | await refreshAfterBecomingActive() |
| 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() | ||
| 52 | } | 38 | } |
| 53 | .onReceive(NotificationCenter.default.publisher(for: .cloudSyncDidApplyChanges)) { _ in | 39 | .onReceive(NotificationCenter.default.publisher(for: .cloudSyncDidApplyChanges)) { _ in |
| 54 | viewModel.refreshPersistedData() | 40 | viewModel.refreshPersistedData() |
| @@ -58,21 +44,30 @@ struct DomainDigApp: App { | |||
| 58 | } | 44 | } |
| 59 | .onChange(of: scenePhase) { _, newValue in | 45 | .onChange(of: scenePhase) { _, newValue in |
| 60 | guard newValue == .active else { return } | 46 | guard newValue == .active else { return } |
| 61 | viewModel.refreshMonitoringState() | 47 | Task { await refreshAfterBecomingActive() } |
| 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() | ||
| 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 | /// Picks up a domain shared via the share extension and routes it into an | 71 | /// Picks up a domain shared via the share extension and routes it into an |
| 77 | /// inspection through the intent router (consumed by `RootTabView`). | 72 | /// inspection through the intent router (consumed by `RootTabView`). |
| 78 | private func consumeShareInbox() { | 73 | private func consumeShareInbox() { |
DomainDig/FeatureAccessService.swift +7 −1
| @@ -85,8 +85,14 @@ struct UpgradePromptContext: Identifiable, Equatable { | |||
| 85 | enum FeatureAccessService { | 85 | enum FeatureAccessService { |
| 86 | private static let effectivelyUnlimitedTrackedDomains = 5_000 | 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 | static var currentTier: FeatureTier { | 94 | static var currentTier: FeatureTier { |
| 89 | PurchaseService.cachedTier | 95 | PurchaseService.shared.currentTier |
| 90 | } | 96 | } |
| 91 | 97 | ||
| 92 | static var entitlements: FeatureEntitlements { | 98 | static var entitlements: FeatureEntitlements { |
DomainDig/RootTabView.swift −2
| @@ -37,8 +37,6 @@ struct RootTabView: View { | |||
| 37 | @State private var selectedTab: RootTab = FeatureAccessService.currentTier == .free ? .inspect : .dashboard | 37 | @State private var selectedTab: RootTab = FeatureAccessService.currentTier == .free ? .inspect : .dashboard |
| 38 | 38 | ||
| 39 | var body: some View { | 39 | var body: some View { |
| 40 | let _ = purchaseService.currentTier | ||
| 41 | |||
| 42 | Group { | 40 | Group { |
| 43 | if horizontalSizeClass == .regular { | 41 | if horizontalSizeClass == .regular { |
| 44 | splitLayout | 42 | splitLayout |
DomainDig/SettingsViews.swift −1
| @@ -11,7 +11,6 @@ struct SettingsView: View { | |||
| 11 | @State private var purchaseService = PurchaseService.shared | 11 | @State private var purchaseService = PurchaseService.shared |
| 12 | 12 | ||
| 13 | var body: some View { | 13 | var body: some View { |
| 14 | let _ = purchaseService.currentTier | ||
| 15 | 14 | ||
| 16 | List { | 15 | List { |
| 17 | Section("Tier") { | 16 | Section("Tier") { |
DomainDig/WatchlistView.swift −2
| @@ -5,7 +5,6 @@ struct WatchlistView: View { | |||
| 5 | @Environment(\.accessibilityReduceMotion) private var reduceMotion | 5 | @Environment(\.accessibilityReduceMotion) private var reduceMotion |
| 6 | @Bindable var viewModel: DomainViewModel | 6 | @Bindable var viewModel: DomainViewModel |
| 7 | @Environment(\.dismiss) private var dismiss | 7 | @Environment(\.dismiss) private var dismiss |
| 8 | @State private var purchaseService = PurchaseService.shared | ||
| 9 | @State private var showWorkflowAddSheet = false | 8 | @State private var showWorkflowAddSheet = false |
| 10 | @State private var showAddDomainSheet = false | 9 | @State private var showAddDomainSheet = false |
| 11 | @State private var newTrackedDomain = "" | 10 | @State private var newTrackedDomain = "" |
| @@ -24,7 +23,6 @@ struct WatchlistView: View { | |||
| 24 | } | 23 | } |
| 25 | 24 | ||
| 26 | var body: some View { | 25 | var body: some View { |
| 27 | let _ = purchaseService.currentTier | ||
| 28 | 26 | ||
| 29 | List { | 27 | List { |
| 30 | if !viewModel.allWatchlistTags.isEmpty { | 28 | if !viewModel.allWatchlistTags.isEmpty { |
DomainDig/WorkflowsView.swift −2
| @@ -10,12 +10,10 @@ private enum WorkflowDestinationMode: String, CaseIterable, Identifiable { | |||
| 10 | struct WorkflowsView: View { | 10 | struct WorkflowsView: View { |
| 11 | @Environment(\.appDensity) private var appDensity | 11 | @Environment(\.appDensity) private var appDensity |
| 12 | @Bindable var viewModel: DomainViewModel | 12 | @Bindable var viewModel: DomainViewModel |
| 13 | @State private var purchaseService = PurchaseService.shared | ||
| 14 | 13 | ||
| 15 | @State private var showingCreateWorkflow = false | 14 | @State private var showingCreateWorkflow = false |
| 16 | 15 | ||
| 17 | var body: some View { | 16 | var body: some View { |
| 18 | let _ = purchaseService.currentTier | ||
| 19 | 17 | ||
| 20 | List { | 18 | List { |
| 21 | if let limitMessage = FeatureAccessService.workflowAllowanceSummary(currentCount: viewModel.workflows.count) { | 19 | if let limitMessage = FeatureAccessService.workflowAllowanceSummary(currentCount: viewModel.workflows.count) { |