From a49d5fea3551bea1482b400ef788e43f705cf65e Mon Sep 17 00:00:00 2001 From: Robin Kutesa Date: Mon, 1 Jun 2026 02:25:35 +0300 Subject: [PATCH] Show overdue + today task count on app icon badge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- KisaniCal/Managers/NotificationManager.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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) {