Skip to content

Commit

Permalink
Snoozing fix (Artificial-Pancreas#207)
Browse files Browse the repository at this point in the history
* Update UserNotificationsManager.swift

Glucose notification function changed to fully snooze, i.e. no pop up at all when snoozed, by @TymHuckin.

* Clean up.

---------

Co-authored-by: TymHuckin <[email protected]>
  • Loading branch information
2 people authored and mountrcg committed Sep 7, 2023
1 parent 1adab13 commit 00643b1
Showing 1 changed file with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ final class BaseUserNotificationsManager: NSObject, UserNotificationsManager, In

ensureCanSendNotification {
var titles: [String] = []

var notificationAlarm = false

switch self.glucoseStorage.alarm {
Expand All @@ -210,32 +209,29 @@ final class BaseUserNotificationsManager: NSObject, UserNotificationsManager, In
notificationAlarm = true
}

if self.snoozeUntilDate > Date() {
titles.append(NSLocalizedString("(Snoozed)", comment: "(Snoozed)"))
notificationAlarm = false
}

let delta = glucose.count >= 2 ? glucoseValue - (glucose[glucose.count - 2].glucose ?? 0) : nil

let body = self.glucoseText(glucoseValue: glucoseValue, delta: delta, direction: lastGlucose.direction) + self
.infoBody()

titles.append(body)

let content = UNMutableNotificationContent()
content.title = titles.joined(separator: " ")
content.body = body
if self.snoozeUntilDate > Date() {
titles.append(NSLocalizedString("(Snoozed)", comment: "(Snoozed)"))
notificationAlarm = false
} else {
titles.append(body)
let content = UNMutableNotificationContent()
content.title = titles.joined(separator: " ")
content.body = body

if notificationAlarm {
self.playSoundIfNeeded()
content.sound = .default
content.userInfo[NotificationAction.key] = NotificationAction.snooze.rawValue
}

if notificationAlarm {
self.playSoundIfNeeded()
content.sound = .default
content.userInfo[NotificationAction.key] = NotificationAction.snooze.rawValue
self.addRequest(identifier: .glucocoseNotification, content: content, deleteOld: true)
}

self.addRequest(identifier: .glucocoseNotification, content: content, deleteOld: true)
}
}

private func glucoseText(glucoseValue: Int, delta: Int?, direction: BloodGlucose.Direction?) -> String {
let units = settingsManager.settings.units
let glucoseText = glucoseFormatter
Expand Down

0 comments on commit 00643b1

Please sign in to comment.