summaryrefslogtreecommitdiff
path: root/DomainDig/LocalNotificationService.swift
diff options
context:
space:
mode:
Diffstat (limited to 'DomainDig/LocalNotificationService.swift')
-rw-r--r--DomainDig/LocalNotificationService.swift33
1 files changed, 33 insertions, 0 deletions
diff --git a/DomainDig/LocalNotificationService.swift b/DomainDig/LocalNotificationService.swift
index 450d844..7b43d67 100644
--- a/DomainDig/LocalNotificationService.swift
+++ b/DomainDig/LocalNotificationService.swift
@@ -27,6 +27,18 @@ final class LocalNotificationService {
}
}
+ func isAuthorizedForAlerts() async -> Bool {
+ let settings = await UNUserNotificationCenter.current().notificationSettings()
+ switch settings.authorizationStatus {
+ case .authorized, .provisional, .ephemeral:
+ return true
+ case .denied, .notDetermined:
+ return false
+ @unknown default:
+ return false
+ }
+ }
+
func notifyDomainEvent(domain: String, message: String, severity: ChangeSeverity) async {
await schedule(
identifier: "domain-change-\(domain)",
@@ -45,6 +57,27 @@ final class LocalNotificationService {
)
}
+ func notifyMonitoringAlert(
+ domain: String,
+ message: String,
+ severity: MonitoringAlertSeverity
+ ) async {
+ let interruptionLevel: UNNotificationInterruptionLevel
+ switch severity {
+ case .critical:
+ interruptionLevel = .timeSensitive
+ case .warning, .info:
+ interruptionLevel = .active
+ }
+
+ await schedule(
+ identifier: "monitoring-\(domain)-\(UUID().uuidString)",
+ title: domain,
+ body: message,
+ interruptionLevel: interruptionLevel
+ )
+ }
+
func notifySweepComplete(summary: BatchSweepSummary) async {
let body = "\(summary.changedDomains) changed, \(summary.warningDomains) warnings, \(summary.unchangedDomains) unchanged"
await schedule(