30 lines
1.0 KiB
Swift
30 lines
1.0 KiB
Swift
|
|
import Foundation
|
||
|
|
|
||
|
|
/// What the menu should tell the user about banner delivery. Pure so it can be tested without
|
||
|
|
/// UserNotifications, which only exists inside an app bundle.
|
||
|
|
public enum BannerPermission: Equatable {
|
||
|
|
case unknown
|
||
|
|
case allowed
|
||
|
|
case denied
|
||
|
|
case notDetermined
|
||
|
|
|
||
|
|
/// `rawValue` is UNAuthorizationStatus: 0 notDetermined, 1 denied, 2 authorized, 3 provisional, 4 ephemeral.
|
||
|
|
public init(authorizationRawValue: Int) {
|
||
|
|
switch authorizationRawValue {
|
||
|
|
case 0: self = .notDetermined
|
||
|
|
case 1: self = .denied
|
||
|
|
case 2, 3, 4: self = .allowed
|
||
|
|
default: self = .unknown
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Nil when nothing needs saying. Unknown stays quiet so the bare-binary dev path shows no warning.
|
||
|
|
public var warning: String? {
|
||
|
|
switch self {
|
||
|
|
case .denied: return "Banners are blocked. Allow luxe Notifier in System Settings > Notifications."
|
||
|
|
case .notDetermined: return "Waiting for notification permission."
|
||
|
|
case .allowed, .unknown: return nil
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|