@@ -407,7 +407,6 @@ final class DeviceDataManager {
407
407
overrideHistory: overrideHistory,
408
408
insulinDeliveryStore: doseStore. insulinDeliveryStore
409
409
)
410
-
411
410
412
411
settingsManager. remoteDataServicesManager = remoteDataServicesManager
413
412
@@ -416,7 +415,10 @@ final class DeviceDataManager {
416
415
alertManager: alertManager,
417
416
analyticsServicesManager: analyticsServicesManager,
418
417
loggingServicesManager: loggingServicesManager,
419
- remoteDataServicesManager: remoteDataServicesManager
418
+ remoteDataServicesManager: remoteDataServicesManager,
419
+ settingsManager: settingsManager,
420
+ servicesManagerDelegate: loopManager,
421
+ servicesManagerDosingDelegate: self
420
422
)
421
423
422
424
let criticalEventLogs : [ CriticalEventLog ] = [ settingsManager. settingsStore, glucoseStore, carbStore, dosingDecisionStore, doseStore, deviceLog, alertManager. alertStore]
@@ -1339,6 +1341,7 @@ extension DeviceDataManager: LoopDataManagerDelegate {
1339
1341
self . crashRecoveryManager. dosingFinished ( )
1340
1342
}
1341
1343
}
1344
+
1342
1345
}
1343
1346
1344
1347
extension Notification . Name {
@@ -1347,152 +1350,14 @@ extension Notification.Name {
1347
1350
static let PumpEventsAdded = Notification . Name ( rawValue: " com.loopKit.notification.PumpEventsAdded " )
1348
1351
}
1349
1352
1350
- // MARK: - Remote Notification Handling
1351
- extension DeviceDataManager {
1352
-
1353
- func handleRemoteNotification( _ notification: [ String : AnyObject ] ) {
1354
- Task {
1355
- let backgroundTask = await beginBackgroundTask ( name: " Remote Data Upload " )
1356
- await handleRemoteNotification ( notification)
1357
- await endBackgroundTask ( backgroundTask)
1358
- }
1359
- }
1360
-
1361
- func handleRemoteNotification( _ notification: [ String : AnyObject ] ) async {
1362
-
1363
- defer {
1364
- log. default ( " Remote Notification: Finished handling " )
1365
- }
1366
-
1367
- guard FeatureFlags . remoteCommandsEnabled else {
1368
- log. error ( " Remote Notification: Remote Commands not enabled. " )
1369
- return
1370
- }
1371
-
1372
- let command : RemoteCommand
1373
- do {
1374
- command = try await remoteDataServicesManager. commandFromPushNotification ( notification)
1375
- } catch {
1376
- log. error ( " Remote Notification: Parse Error: %{public}@ " , String ( describing: error) )
1377
- return
1378
- }
1379
-
1380
- await handleRemoteCommand ( command)
1381
- }
1382
-
1383
- func handleRemoteCommand( _ command: RemoteCommand ) async {
1384
-
1385
- log. default ( " Remote Notification: Handling command %{public}@ " , String ( describing: command) )
1386
-
1387
- switch command. action {
1388
- case . temporaryScheduleOverride( let overrideAction) :
1389
- do {
1390
- try command. validate ( )
1391
- try await handleOverrideAction ( overrideAction)
1392
- } catch {
1393
- log. error ( " Remote Notification: Override Action Error: %{public}@ " , String ( describing: error) )
1394
- }
1395
- case . cancelTemporaryOverride( let overrideCancelAction) :
1396
- do {
1397
- try command. validate ( )
1398
- try await handleOverrideCancelAction ( overrideCancelAction)
1399
- } catch {
1400
- log. error ( " Remote Notification: Override Action Cancel Error: %{public}@ " , String ( describing: error) )
1401
- }
1402
- case . bolusEntry( let bolusAction) :
1403
- do {
1404
- try command. validate ( )
1405
- try await handleBolusAction ( bolusAction)
1406
- } catch {
1407
- await NotificationManager . sendRemoteBolusFailureNotification ( for: error, amount: bolusAction. amountInUnits)
1408
- log. error ( " Remote Notification: Bolus Action Error: %{public}@ " , String ( describing: error) )
1409
- }
1410
- case . carbsEntry( let carbAction) :
1411
- do {
1412
- try command. validate ( )
1413
- try await handleCarbAction ( carbAction)
1414
- } catch {
1415
- await NotificationManager . sendRemoteCarbEntryFailureNotification ( for: error, amountInGrams: carbAction. amountInGrams)
1416
- log. error ( " Remote Notification: Carb Action Error: %{public}@ " , String ( describing: error) )
1417
- }
1418
- }
1419
- }
1420
-
1421
- //Remote Overrides
1422
-
1423
- func handleOverrideAction( _ action: OverrideAction ) async throws {
1424
- let remoteOverride = try action. toValidOverride ( allowedPresets: loopManager. settings. overridePresets)
1425
- await activateRemoteOverride ( remoteOverride)
1426
- }
1427
-
1428
- func handleOverrideCancelAction( _ action: OverrideCancelAction ) async throws {
1429
- await activateRemoteOverride ( nil )
1430
- }
1431
-
1432
- func activateRemoteOverride( _ remoteOverride: TemporaryScheduleOverride ? ) async {
1433
- loopManager. mutateSettings { settings in settings. scheduleOverride = remoteOverride }
1434
- await remoteDataServicesManager. triggerUpload ( for: . overrides)
1435
- }
1436
-
1437
- //Remote Bolus
1438
-
1439
- func handleBolusAction( _ action: BolusAction ) async throws {
1440
- let validBolusAmount = try action. toValidBolusAmount ( maximumBolus: loopManager. settings. maximumBolus)
1441
- try await self . enactBolus ( units: validBolusAmount, activationType: . manualNoRecommendation)
1442
- await remoteDataServicesManager. triggerUpload ( for: . dose)
1443
- self . analyticsServicesManager. didBolus ( source: " Remote " , units: validBolusAmount)
1444
- }
1445
-
1446
- //Remote Carb Entry
1447
-
1448
- func handleCarbAction( _ action: CarbAction ) async throws {
1449
- let candidateCarbEntry = try action. toValidCarbEntry ( defaultAbsorptionTime: carbStore. defaultAbsorptionTimes. medium,
1450
- minAbsorptionTime: LoopConstants . minCarbAbsorptionTime,
1451
- maxAbsorptionTime: LoopConstants . maxCarbAbsorptionTime,
1452
- maxCarbEntryQuantity: LoopConstants . maxCarbEntryQuantity. doubleValue ( for: . gram( ) ) ,
1453
- maxCarbEntryPastTime: LoopConstants . maxCarbEntryPastTime,
1454
- maxCarbEntryFutureTime: LoopConstants . maxCarbEntryFutureTime
1455
- )
1456
-
1457
- let _ = try await addRemoteCarbEntry ( candidateCarbEntry)
1458
- await remoteDataServicesManager. triggerUpload ( for: . carb)
1459
- }
1460
-
1461
- //Can't add this concurrency wrapper method to LoopKit due to the minimum iOS version
1462
- func addRemoteCarbEntry( _ carbEntry: NewCarbEntry ) async throws -> StoredCarbEntry {
1463
- return try await withCheckedThrowingContinuation { continuation in
1464
- carbStore. addCarbEntry ( carbEntry) { result in
1465
- switch result {
1466
- case . success( let storedCarbEntry) :
1467
- self . analyticsServicesManager. didAddCarbs ( source: " Remote " , amount: carbEntry. quantity. doubleValue ( for: . gram( ) ) )
1468
- continuation. resume ( returning: storedCarbEntry)
1469
- case . failure( let error) :
1470
- continuation. resume ( throwing: error)
1471
- }
1472
- }
1473
- }
1474
- }
1475
-
1476
- //Background Uploads
1353
+ // MARK: - ServicesManagerDosingDelegate
1354
+
1355
+ extension DeviceDataManager : ServicesManagerDosingDelegate {
1477
1356
1478
- func beginBackgroundTask( name: String ) async -> UIBackgroundTaskIdentifier ? {
1479
- var backgroundTask : UIBackgroundTaskIdentifier ?
1480
- backgroundTask = await UIApplication . shared. beginBackgroundTask ( withName: name) {
1481
- guard let backgroundTask = backgroundTask else { return }
1482
- Task {
1483
- await UIApplication . shared. endBackgroundTask ( backgroundTask)
1484
- }
1485
-
1486
- self . log. error ( " Background Task Expired: %{public}@ " , name)
1487
- }
1488
-
1489
- return backgroundTask
1357
+ func deliverBolus( amountInUnits: Double ) async throws {
1358
+ try await enactBolus ( units: amountInUnits, activationType: . manualNoRecommendation)
1490
1359
}
1491
1360
1492
- func endBackgroundTask( _ backgroundTask: UIBackgroundTaskIdentifier ? ) async {
1493
- guard let backgroundTask else { return }
1494
- await UIApplication . shared. endBackgroundTask ( backgroundTask)
1495
- }
1496
1361
}
1497
1362
1498
1363
// MARK: - Critical Event Log Export
0 commit comments