Commit 13a84c4243

13a84c4243c20d2f8b91a8392033cee4dde2a43e

parent: ba7bcc961b

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-24 06:13 UTC

Make entitlement reads observable

FeatureAccessService.currentTier read PurchaseService.cachedTier, a static over
UserDefaults, so a view body calling hasAccess touched no observable property
and SwiftUI recorded no dependency. Nine `let _ = purchaseService.currentTier`
discards existed to manufacture one. Reading the observable instance instead
makes every existing call site update on its own, because observation records
any observable read while a body evaluates, however deep the call tree.

Four of those nine sat in DomainDigApp's .task, which observation does not
track at all — they never did anything.

Three views lose a @State property they only held in order to perform the fake
read.

Launch and foreground also carried near-duplicates of the same work, and the
foreground copy left out refreshEntitlements() — so a purchase or cancellation
made outside the app was not picked up until the next cold launch. Both now
call one refreshAfterBecomingActive().

Layout: unified · split

DomainDig/ContentView.swift −3
@@ -32,7 +32,6 @@ private struct WorkflowNavigationTarget: Hashable {
3232struct ContentView: View {
3333 @Environment(\.appDensity) private var appDensity
3434 @Bindable var viewModel: DomainViewModel
35 @State private var purchaseService = PurchaseService.shared
3635 @State private var navigationPath = NavigationPath()
3736 @FocusState private var focusedInputField: LookupInputField?
3837 @State private var customPortInput = ""
@@ -48,8 +47,6 @@ struct ContentView: View {
4847 @State private var auditStartInFlight = false
4948
5049 var body: some View {
51 let _ = purchaseService.currentTier
52
5350 NavigationStack(path: $navigationPath) {
5451 ScrollView(.vertical) {
5552 VStack(spacing: 0) {
DomainDig/DomainDigApp.swift +22 −27
@@ -34,21 +34,7 @@ struct DomainDigApp: App {
3434 #if DEBUG
3535 viewModel.seedAuditFixturesIfRequested()
3636 #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()
5238 }
5339 .onReceive(NotificationCenter.default.publisher(for: .cloudSyncDidApplyChanges)) { _ in
5440 viewModel.refreshPersistedData()
@@ -58,21 +44,30 @@ struct DomainDigApp: App {
5844 }
5945 .onChange(of: scenePhase) { _, newValue in
6046 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() }
7348 }
7449 }
7550
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
7671 /// Picks up a domain shared via the share extension and routes it into an
7772 /// inspection through the intent router (consumed by `RootTabView`).
7873 private func consumeShareInbox() {
DomainDig/FeatureAccessService.swift +7 −1
@@ -85,8 +85,14 @@ struct UpgradePromptContext: Identifiable, Equatable {
8585enum FeatureAccessService {
8686 private static let effectivelyUnlimitedTrackedDomains = 5_000
8787
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.
8894 static var currentTier: FeatureTier {
89 PurchaseService.cachedTier
95 PurchaseService.shared.currentTier
9096 }
9197
9298 static var entitlements: FeatureEntitlements {
DomainDig/RootTabView.swift −2
@@ -37,8 +37,6 @@ struct RootTabView: View {
3737 @State private var selectedTab: RootTab = FeatureAccessService.currentTier == .free ? .inspect : .dashboard
3838
3939 var body: some View {
40 let _ = purchaseService.currentTier
41
4240 Group {
4341 if horizontalSizeClass == .regular {
4442 splitLayout
DomainDig/SettingsViews.swift −1
@@ -11,7 +11,6 @@ struct SettingsView: View {
1111 @State private var purchaseService = PurchaseService.shared
1212
1313 var body: some View {
14 let _ = purchaseService.currentTier
1514
1615 List {
1716 Section("Tier") {
DomainDig/WatchlistView.swift −2
@@ -5,7 +5,6 @@ struct WatchlistView: View {
55 @Environment(\.accessibilityReduceMotion) private var reduceMotion
66 @Bindable var viewModel: DomainViewModel
77 @Environment(\.dismiss) private var dismiss
8 @State private var purchaseService = PurchaseService.shared
98 @State private var showWorkflowAddSheet = false
109 @State private var showAddDomainSheet = false
1110 @State private var newTrackedDomain = ""
@@ -24,7 +23,6 @@ struct WatchlistView: View {
2423 }
2524
2625 var body: some View {
27 let _ = purchaseService.currentTier
2826
2927 List {
3028 if !viewModel.allWatchlistTags.isEmpty {
DomainDig/WorkflowsView.swift −2
@@ -10,12 +10,10 @@ private enum WorkflowDestinationMode: String, CaseIterable, Identifiable {
1010struct WorkflowsView: View {
1111 @Environment(\.appDensity) private var appDensity
1212 @Bindable var viewModel: DomainViewModel
13 @State private var purchaseService = PurchaseService.shared
1413
1514 @State private var showingCreateWorkflow = false
1615
1716 var body: some View {
18 let _ = purchaseService.currentTier
1917
2018 List {
2119 if let limitMessage = FeatureAccessService.workflowAllowanceSummary(currentCount: viewModel.workflows.count) {