diff --git a/KisaniCal/Managers/NotificationManager.swift b/KisaniCal/Managers/NotificationManager.swift index 16e2436..7f3b66f 100644 --- a/KisaniCal/Managers/NotificationManager.swift +++ b/KisaniCal/Managers/NotificationManager.swift @@ -51,9 +51,22 @@ final class NotificationManager: NSObject, ObservableObject, @unchecked Sendable guard ok else { return } self.scheduleWorkout(schedule: schedule, programs: programs, progress: progress) self.scheduleTasks(snapshot: tasks) + self.updateBadge(snapshot: tasks) } } + // MARK: - Badge + + private func updateBadge(snapshot: [TaskItem]) { + let startOfDay = Calendar.current.startOfDay(for: Date()) + let tomorrow = Calendar.current.date(byAdding: .day, value: 1, to: startOfDay)! + let count = snapshot.filter { t in + guard !t.isComplete, let due = t.dueDate else { return false } + return due < tomorrow // overdue or due today + }.count + center.setBadgeCount(count) { _ in } + } + // MARK: - Workout reminders + check-in private func scheduleWorkout(schedule: [Int: UUID], programs: [WorkoutProgram], progress: Double) {