// The OS conversation `/settings#notifications` needs, which is 4j's plus one.//// Only the half the settings screen uses. `read` and `ask` are NOT redeclared// here: they are// `CottonKit.NotificationAuthority`'s, and this refines that protocol rather// than standing beside it, so there is exactly one answer in the app to "what// does iOS think?" and the settings screen cannot drift from the reminder// pass's reading of it.//// The one addition is `openSystemSettings()`. It belongs to this screen alone:// the way out of `denied` is the iOS Settings app, and the *only* place the app// offers that door is the blocked-permission card here. 4j never needed it —// nothing it does can be fixed by sending a person to Settings — which is why// the method is added by the screen that has the button rather than pushed down// into a protocol every reminder caller would then have to implement.importFoundation#if canImport(UIKit)import UIKit#endifimportCottonKit/// `NotificationAuthority`, plus the door out of `denied`.publicprotocolNotificationSettingsAuthority: NotificationAuthority {/// Open the app's page in the iOS Settings app. Nothing to report if it/// refuses — the empty catch, kept. @MainActor func openSystemSettings()}/// The real one. `read` / `ask` / `registerForRemoteNotifications` are 4j's/// `SystemNotificationAuthority` verbatim, held rather than reimplemented so a/// change to how the app reads iOS's answer lands in ONE place.publicstructSystemNotificationSettingsAuthority: NotificationSettingsAuthority {privatelet base = SystemNotificationAuthority()publicinit() {}publicfunc read() async -> NotificationPermission { await base.read() }publicfunc ask() async -> NotificationPermission { await base.ask() }publicfunc registerForRemoteNotifications() async { await base.registerForRemoteNotifications() } @MainActor publicfunc openSystemSettings() { #if canImport(UIKit)guardlet url = URL(string: UIApplication.openSettingsURLString) else { return } UIApplication.shared.open(url) #endif }}/// The double. Answers what a test scripts, and counts the doors it was asked/// to open — `@unchecked Sendable` with a lock because a test drives it from/// the MainActor while the model reads it from a task.publicfinalclassScriptedNotificationSettingsAuthority: NotificationSettingsAuthority, @unchecked Sendable {privatelet lock = NSLock()privatevar answers: [NotificationPermission]privatevar asked = 0privatevar opened = 0/// The broadcast this double fires on `ask`, mirroring/// `SystemNotificationSettingsAuthority`. Optional because most tests do/// not care; passed when the test is ABOUT the broadcast, so "once per ask"/// stays assertable without a real `UNUserNotificationCenter`.privatelet changes: NotificationPermissionChanges?/// `answers` is consumed one per `read`/`ask`; the last one repeats, so a/// test that only cares about the steady state passes one.publicinit(_ answers: [NotificationPermission], changes: NotificationPermissionChanges? = nil) {self.answers = answersself.changes = changes }privatefunc next() -> NotificationPermission { lock.withLock {guardlet head = answers.first else { return .undetermined }if answers.count > 1 { answers.removeFirst() }return head } }publicfunc read() async -> NotificationPermission { next() }publicfunc ask() async -> NotificationPermission { lock.withLock { asked += 1 }// Same shape as the real one: once per ask, whatever the answer.defer { changes?.notify() }return next() }publicfunc registerForRemoteNotifications() async {} @MainActor publicfunc openSystemSettings() { lock.withLock { opened += 1 } }/// How many times the prompt was spent. iOS grants one per install, so a/// test that this screen never spends a second is worth having.publicvar timesAsked: Int { lock.withLock { asked } }publicvar timesOpenedSettings: Int { lock.withLock { opened } }}