Skip to content

Commit ac9c150

Browse files
authored
Improve error message display (#769)
* Improve error message display * update revision of rlkit used
1 parent f4a12e5 commit ac9c150

File tree

8 files changed

+73
-7
lines changed

8 files changed

+73
-7
lines changed

Cartfile.resolved

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
github "LoopKit/Amplitude-iOS" "2137d5fd44bf630ed33e1e72d7af6d8f8612f270"
22
github "LoopKit/CGMBLEKit" "1f9d0f221b886f12bcb2c46dc0b551589b623210"
3-
github "LoopKit/LoopKit" "7082c64333113ad83238e483e83029c161ac35bb"
3+
github "LoopKit/LoopKit" "16fc21d01a7bf0758c6c81dbb25a5168588c9e30"
44
github "i-schuetz/SwiftCharts" "0.6.1"
55
github "mddub/G4ShareSpy" "v0.3.3"
66
github "mddub/dexcom-share-client-swift" "v0.4.1"
7-
github "ps2/rileylink_ios" "4a714a59d399aeb2984cbbe0434f02e6b59cfec5"
7+
github "ps2/rileylink_ios" "143da3be985a98e602b15761f0cb0a092eaa9300"

Common/Extensions/OSLog.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ extension OSLog {
2121
log(message, type: .info, args)
2222
}
2323

24+
func `default`(_ message: StaticString, _ args: CVarArg...) {
25+
log(message, type: .default, args)
26+
}
27+
2428
func error(_ message: StaticString, _ args: CVarArg...) {
2529
log(message, type: .error, args)
2630
}
@@ -35,6 +39,10 @@ extension OSLog {
3539
os_log(message, log: self, type: type, args[0], args[1])
3640
case 3:
3741
os_log(message, log: self, type: type, args[0], args[1], args[2])
42+
case 4:
43+
os_log(message, log: self, type: type, args[0], args[1], args[2], args[3])
44+
case 5:
45+
os_log(message, log: self, type: type, args[0], args[1], args[2], args[3], args[4])
3846
default:
3947
os_log(message, log: self, type: type, args)
4048
}

Loop/Managers/CGM/DexCGMManager.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,13 @@ enum CalibrationError: Error {
372372

373373
extension CalibrationError: LocalizedError {
374374
var errorDescription: String? {
375+
switch self {
376+
case .unreliableState:
377+
return NSLocalizedString("Glucose data is unavailable", comment: "Error description for unreliable state")
378+
}
379+
}
380+
381+
var failureReason: String? {
375382
switch self {
376383
case .unreliableState(let state):
377384
return state.localizedDescription

Loop/Managers/DeviceDataManager.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ extension DeviceDataManager: PumpManagerDelegate {
170170
if let newValue = pumpManager.pumpBatteryChargeRemaining {
171171
if newValue == 0 {
172172
NotificationManager.sendPumpBatteryLowNotification()
173+
} else {
174+
NotificationManager.clearPumpBatteryLowNotification()
173175
}
174176

175177
if let oldValue = oldValue, newValue - oldValue >= 0.5 {
@@ -246,14 +248,20 @@ extension DeviceDataManager: PumpManagerDelegate {
246248
return
247249
}
248250

251+
var didSendLowNotification = false
249252
let warningThresholds: [Double] = [10, 20, 30]
250253

251254
for threshold in warningThresholds {
252255
if newValue.unitVolume <= threshold && previousVolume > threshold {
253256
NotificationManager.sendPumpReservoirLowNotificationForAmount(newValue.unitVolume, andTimeRemaining: nil)
257+
didSendLowNotification = true
254258
}
255259
}
256260

261+
if !didSendLowNotification {
262+
NotificationManager.clearPumpReservoirNotification()
263+
}
264+
257265
if newValue.unitVolume > previousVolume + 1 {
258266
AnalyticsManager.shared.reservoirWasRewound()
259267
}

Loop/Managers/DiagnosticLogger.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import Foundation
1010
import os.log
11+
import LoopKit
1112

1213

1314
final class DiagnosticLogger {
@@ -106,6 +107,11 @@ final class CategoryLogger {
106107
remoteLog(.info, message: message)
107108
}
108109

110+
func `default`(_ message: String) {
111+
systemLog.info("%{public}@", message)
112+
remoteLog(.default, message: message)
113+
}
114+
109115
func error(_ message: [String: Any]) {
110116
systemLog.error("%{public}@", String(reflecting: message))
111117
remoteLog(.error, message: message)

Loop/Managers/LoopDataManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ final class LoopDataManager {
189189
set {
190190
lockedLastLoopCompleted.value = newValue
191191

192+
NotificationManager.clearLoopNotRunningNotifications()
192193
NotificationManager.scheduleLoopNotRunningNotifications()
193194
AnalyticsManager.shared.loopDidSucceed()
194195
}

Loop/Managers/NotificationManager.swift

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,25 @@ struct NotificationManager {
6363

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

66+
let sentenceFormat = NSLocalizedString("%@.", comment: "Appends a full-stop to a statement")
67+
6668
switch error {
6769
case let error as SetBolusError:
6870
notification.subtitle = error.errorDescriptionWithUnits(units)
69-
notification.body = String(format: "%@ %@", error.failureReason!, error.recoverySuggestion!)
71+
72+
let body = [error.failureReason, error.recoverySuggestion].compactMap({ $0 }).map({
73+
String(format: sentenceFormat, $0)
74+
}).joined(separator: " ")
75+
76+
notification.body = body
7077
case let error as LocalizedError:
71-
notification.body = error.errorDescription ?? error.localizedDescription
78+
if let subtitle = error.errorDescription {
79+
notification.subtitle = subtitle
80+
}
81+
let message = [error.failureReason, error.recoverySuggestion].compactMap({ $0 }).map({
82+
String(format: sentenceFormat, $0)
83+
}).joined(separator: "\n")
84+
notification.body = message.isEmpty ? String(describing: error) : message
7285
default:
7386
notification.body = error.localizedDescription
7487
}
@@ -134,6 +147,19 @@ struct NotificationManager {
134147
}
135148
}
136149

150+
static func clearLoopNotRunningNotifications() {
151+
// Clear out any existing not-running notifications
152+
UNUserNotificationCenter.current().getDeliveredNotifications { (notifications) in
153+
let loopNotRunningIdentifiers = notifications.filter({
154+
$0.request.content.categoryIdentifier == Category.loopNotRunning.rawValue
155+
}).map({
156+
$0.request.identifier
157+
})
158+
159+
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: loopNotRunningIdentifiers)
160+
}
161+
}
162+
137163
static func sendPumpBatteryLowNotification() {
138164
let notification = UNMutableNotificationContent()
139165

@@ -151,6 +177,10 @@ struct NotificationManager {
151177
UNUserNotificationCenter.current().add(request)
152178
}
153179

180+
static func clearPumpBatteryLowNotification() {
181+
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [Category.pumpBatteryLow.rawValue])
182+
}
183+
154184
static func sendPumpReservoirEmptyNotification() {
155185
let notification = UNMutableNotificationContent()
156186

@@ -200,4 +230,8 @@ struct NotificationManager {
200230

201231
UNUserNotificationCenter.current().add(request)
202232
}
233+
234+
static func clearPumpReservoirNotification() {
235+
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [Category.pumpReservoirLow.rawValue])
236+
}
203237
}

Loop/View Controllers/SettingsTableViewController.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ final class SettingsTableViewController: UITableViewController {
2828
}
2929

3030
override func viewWillAppear(_ animated: Bool) {
31-
// Manually invoke the delegate for rows deselecting on appear
32-
for indexPath in tableView.indexPathsForSelectedRows ?? [] {
33-
_ = tableView(tableView, willDeselectRowAt: indexPath)
31+
if clearsSelectionOnViewWillAppear {
32+
// Manually invoke the delegate for rows deselecting on appear
33+
for indexPath in tableView.indexPathsForSelectedRows ?? [] {
34+
_ = tableView(tableView, willDeselectRowAt: indexPath)
35+
}
3436
}
3537

3638
super.viewWillAppear(animated)

0 commit comments

Comments
 (0)