Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github "LoopKit/Amplitude-iOS" "2137d5fd44bf630ed33e1e72d7af6d8f8612f270"
github "LoopKit/CGMBLEKit" "1f9d0f221b886f12bcb2c46dc0b551589b623210"
github "LoopKit/LoopKit" "7082c64333113ad83238e483e83029c161ac35bb"
github "LoopKit/LoopKit" "16fc21d01a7bf0758c6c81dbb25a5168588c9e30"
github "i-schuetz/SwiftCharts" "0.6.1"
github "mddub/G4ShareSpy" "v0.3.3"
github "mddub/dexcom-share-client-swift" "v0.4.1"
github "ps2/rileylink_ios" "4a714a59d399aeb2984cbbe0434f02e6b59cfec5"
github "ps2/rileylink_ios" "143da3be985a98e602b15761f0cb0a092eaa9300"
8 changes: 8 additions & 0 deletions Common/Extensions/OSLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ extension OSLog {
log(message, type: .info, args)
}

func `default`(_ message: StaticString, _ args: CVarArg...) {
log(message, type: .default, args)
}

func error(_ message: StaticString, _ args: CVarArg...) {
log(message, type: .error, args)
}
Expand All @@ -35,6 +39,10 @@ extension OSLog {
os_log(message, log: self, type: type, args[0], args[1])
case 3:
os_log(message, log: self, type: type, args[0], args[1], args[2])
case 4:
os_log(message, log: self, type: type, args[0], args[1], args[2], args[3])
case 5:
os_log(message, log: self, type: type, args[0], args[1], args[2], args[3], args[4])
default:
os_log(message, log: self, type: type, args)
}
Expand Down
7 changes: 7 additions & 0 deletions Loop/Managers/CGM/DexCGMManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,13 @@ enum CalibrationError: Error {

extension CalibrationError: LocalizedError {
var errorDescription: String? {
switch self {
case .unreliableState:
return NSLocalizedString("Glucose data is unavailable", comment: "Error description for unreliable state")
}
}

var failureReason: String? {
switch self {
case .unreliableState(let state):
return state.localizedDescription
Expand Down
8 changes: 8 additions & 0 deletions Loop/Managers/DeviceDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ extension DeviceDataManager: PumpManagerDelegate {
if let newValue = pumpManager.pumpBatteryChargeRemaining {
if newValue == 0 {
NotificationManager.sendPumpBatteryLowNotification()
} else {
NotificationManager.clearPumpBatteryLowNotification()
}

if let oldValue = oldValue, newValue - oldValue >= 0.5 {
Expand Down Expand Up @@ -246,14 +248,20 @@ extension DeviceDataManager: PumpManagerDelegate {
return
}

var didSendLowNotification = false
let warningThresholds: [Double] = [10, 20, 30]

for threshold in warningThresholds {
if newValue.unitVolume <= threshold && previousVolume > threshold {
NotificationManager.sendPumpReservoirLowNotificationForAmount(newValue.unitVolume, andTimeRemaining: nil)
didSendLowNotification = true
}
}

if !didSendLowNotification {
NotificationManager.clearPumpReservoirNotification()
}

if newValue.unitVolume > previousVolume + 1 {
AnalyticsManager.shared.reservoirWasRewound()
}
Expand Down
6 changes: 6 additions & 0 deletions Loop/Managers/DiagnosticLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation
import os.log
import LoopKit


final class DiagnosticLogger {
Expand Down Expand Up @@ -106,6 +107,11 @@ final class CategoryLogger {
remoteLog(.info, message: message)
}

func `default`(_ message: String) {
systemLog.info("%{public}@", message)
remoteLog(.default, message: message)
}

func error(_ message: [String: Any]) {
systemLog.error("%{public}@", String(reflecting: message))
remoteLog(.error, message: message)
Expand Down
1 change: 1 addition & 0 deletions Loop/Managers/LoopDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ final class LoopDataManager {
set {
lockedLastLoopCompleted.value = newValue

NotificationManager.clearLoopNotRunningNotifications()
NotificationManager.scheduleLoopNotRunningNotifications()
AnalyticsManager.shared.loopDidSucceed()
}
Expand Down
38 changes: 36 additions & 2 deletions Loop/Managers/NotificationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,25 @@ struct NotificationManager {

notification.title = NSLocalizedString("Bolus", comment: "The notification title for a bolus failure")

let sentenceFormat = NSLocalizedString("%@.", comment: "Appends a full-stop to a statement")

switch error {
case let error as SetBolusError:
notification.subtitle = error.errorDescriptionWithUnits(units)
notification.body = String(format: "%@ %@", error.failureReason!, error.recoverySuggestion!)

let body = [error.failureReason, error.recoverySuggestion].compactMap({ $0 }).map({
String(format: sentenceFormat, $0)
}).joined(separator: " ")

notification.body = body
case let error as LocalizedError:
notification.body = error.errorDescription ?? error.localizedDescription
if let subtitle = error.errorDescription {
notification.subtitle = subtitle
}
let message = [error.failureReason, error.recoverySuggestion].compactMap({ $0 }).map({
String(format: sentenceFormat, $0)
}).joined(separator: "\n")
notification.body = message.isEmpty ? String(describing: error) : message
default:
notification.body = error.localizedDescription
}
Expand Down Expand Up @@ -134,6 +147,19 @@ struct NotificationManager {
}
}

static func clearLoopNotRunningNotifications() {
// Clear out any existing not-running notifications
UNUserNotificationCenter.current().getDeliveredNotifications { (notifications) in
let loopNotRunningIdentifiers = notifications.filter({
$0.request.content.categoryIdentifier == Category.loopNotRunning.rawValue
}).map({
$0.request.identifier
})

UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: loopNotRunningIdentifiers)
}
}

static func sendPumpBatteryLowNotification() {
let notification = UNMutableNotificationContent()

Expand All @@ -151,6 +177,10 @@ struct NotificationManager {
UNUserNotificationCenter.current().add(request)
}

static func clearPumpBatteryLowNotification() {
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [Category.pumpBatteryLow.rawValue])
}

static func sendPumpReservoirEmptyNotification() {
let notification = UNMutableNotificationContent()

Expand Down Expand Up @@ -200,4 +230,8 @@ struct NotificationManager {

UNUserNotificationCenter.current().add(request)
}

static func clearPumpReservoirNotification() {
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [Category.pumpReservoirLow.rawValue])
}
}
8 changes: 5 additions & 3 deletions Loop/View Controllers/SettingsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ final class SettingsTableViewController: UITableViewController {
}

override func viewWillAppear(_ animated: Bool) {
// Manually invoke the delegate for rows deselecting on appear
for indexPath in tableView.indexPathsForSelectedRows ?? [] {
_ = tableView(tableView, willDeselectRowAt: indexPath)
if clearsSelectionOnViewWillAppear {
// Manually invoke the delegate for rows deselecting on appear
for indexPath in tableView.indexPathsForSelectedRows ?? [] {
_ = tableView(tableView, willDeselectRowAt: indexPath)
}
}

super.viewWillAppear(animated)
Expand Down