@@ -24,6 +24,10 @@ enum CapabilityAuthorizationStatus: Equatable, Sendable {
2424}
2525
2626enum PermissionManager {
27+ static func isNotificationAuthorized ( status : UNAuthorizationStatus ) -> Bool {
28+ status == . authorized || status == . provisional
29+ }
30+
2731 static func isLocationAuthorized ( status : CLAuthorizationStatus , requireAlways : Bool ) -> Bool {
2832 if requireAlways { return status == . authorizedAlways }
2933 switch status {
@@ -73,24 +77,19 @@ enum PermissionManager {
7377 private static func ensureNotifications ( interactive : Bool ) async -> Bool {
7478 let center = UNUserNotificationCenter . current ( )
7579 let settings = await center . notificationSettings ( )
76-
77- switch settings . authorizationStatus {
78- case . authorized , . provisional , . ephemeral :
80+ if self . isNotificationAuthorized ( status : settings . authorizationStatus ) {
7981 return true
80- case . notDetermined :
82+ }
83+ if settings . authorizationStatus == . notDetermined {
8184 guard interactive else { return false }
8285 let granted = await ( try? center . requestAuthorization ( options : [ . alert , . sound , . badge ] ) ) ?? false
8386 let updated = await center . notificationSettings ( )
84- return granted &&
85- ( updated . authorizationStatus == . authorized || updated . authorizationStatus == . provisional )
86- case . denied :
87- if interactive {
88- NotificationPermissionHelper . openSettings ( )
89- }
90- return false
91- @ unknown default :
92- return false
87+ return granted && self . isNotificationAuthorized ( status : updated . authorizationStatus )
88+ }
89+ if settings . authorizationStatus == . denied , interactive {
90+ NotificationPermissionHelper . openSettings ( )
9391 }
92+ return false
9493 }
9594
9695 private static func ensureAppleScript ( interactive : Bool ) async -> Bool {
@@ -216,8 +215,8 @@ enum PermissionManager {
216215 case . notifications :
217216 let center = UNUserNotificationCenter . current ( )
218217 let settings = await center . notificationSettings ( )
219- results [ cap ] = settings . authorizationStatus == . authorized
220- || settings . authorizationStatus == . provisional ? . granted : . notGranted
218+ results [ cap ] = self . isNotificationAuthorized ( status : settings . authorizationStatus )
219+ ? . granted : . notGranted
221220
222221 case . appleScript :
223222 results [ cap ] = await TerminalAutomationPermission . authorizationStatus ( )
0 commit comments