Show overdue + today task count on app icon badge

updateBadge() counts all incomplete tasks with a due date earlier
than tomorrow (i.e. overdue or due today) and calls setBadgeCount().
Called inside reschedule() so the badge updates on foreground, task
changes, and workout set completions — same triggers as notifications.

Co-Authored-By: Kutesir <tqwyy79vzn@privaterelay.appleid.com>
This commit is contained in:
Robin Kutesa
2026-06-01 02:25:35 +03:00
parent 8f8825ac04
commit a49d5fea35

View File

@@ -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) {