Просмотр исходного кода

Fix crash when glucose values cannot be unwrapped in NotificationsManager

dnzxy 2 лет назад
Родитель
Сommit
8e90e4144d
1 измененных файлов с 3 добавлено и 2 удалено
  1. 3 2
      FreeAPS/Sources/Services/UserNotifiactions/UserNotificationsManager.swift

+ 3 - 2
FreeAPS/Sources/Services/UserNotifiactions/UserNotificationsManager.swift

@@ -200,6 +200,7 @@ final class BaseUserNotificationsManager: NSObject, UserNotificationsManager, In
 
 
         context.perform {
         context.perform {
             guard let glucose = self.fetchGlucose(), let lastValue = glucose.first, let lastReading = glucose.first?.glucose,
             guard let glucose = self.fetchGlucose(), let lastValue = glucose.first, let lastReading = glucose.first?.glucose,
+                  let lastDirection = lastValue.direction,
                   let secondLastReading = glucose.dropFirst().first?.glucose else { return }
                   let secondLastReading = glucose.dropFirst().first?.glucose else { return }
 
 
             self.addAppBadge(glucose: (glucose.first?.glucose).map { Int($0) })
             self.addAppBadge(glucose: (glucose.first?.glucose).map { Int($0) })
@@ -225,9 +226,9 @@ final class BaseUserNotificationsManager: NSObject, UserNotificationsManager, In
 
 
                 let delta = glucose.count >= 2 ? lastReading - secondLastReading : nil
                 let delta = glucose.count >= 2 ? lastReading - secondLastReading : nil
                 let body = self.glucoseText(
                 let body = self.glucoseText(
-                    glucoseValue: (glucose.first?.glucose).map { Int($0) } ?? 0,
+                    glucoseValue: Int(lastReading),
                     delta: Int(delta ?? 0),
                     delta: Int(delta ?? 0),
-                    direction: lastValue.direction
+                    direction: lastDirection
                 ) + self
                 ) + self
                     .infoBody()
                     .infoBody()