@@ -811,7 +811,11 @@ extension LoopDataManager {
811811 self . dosingDecisionStore. storeDosingDecision ( dosingDecision) { }
812812 }
813813
814- func storeSettings( ) {
814+ func storeSettings( notificationSettings: NotificationSettings ? = nil ,
815+ controllerDevice: StoredSettings . ControllerDevice ? = nil ,
816+ cgmDevice: HKDevice ? = nil ,
817+ pumpDevice: HKDevice ? = nil )
818+ {
815819 guard let appGroup = UserDefaults . appGroup, let loopSettings = appGroup. loopSettings else {
816820 return
817821 }
@@ -828,12 +832,17 @@ extension LoopDataManager {
828832 maximumBolus: loopSettings. maximumBolus,
829833 suspendThreshold: loopSettings. suspendThreshold,
830834 deviceToken: loopSettings. deviceToken? . hexadecimalString,
835+ insulinType: delegate? . pumpManagerStatus? . insulinType,
831836 defaultRapidActingModel: appGroup. defaultRapidActingModel. map ( StoredInsulinModel . init) ,
832837 basalRateSchedule: appGroup. basalRateSchedule,
833838 insulinSensitivitySchedule: appGroup. insulinSensitivitySchedule,
834839 carbRatioSchedule: appGroup. carbRatioSchedule,
840+ notificationSettings: notificationSettings ?? settingsStore. latestSettings? . notificationSettings,
841+ controllerDevice: controllerDevice ?? UIDevice . current. controllerDevice,
842+ cgmDevice: cgmDevice ?? delegate? . cgmManagerStatus? . device,
843+ pumpDevice: pumpDevice ?? delegate? . pumpManagerStatus? . device,
835844 bloodGlucoseUnit: loopSettings. glucoseUnit)
836- self . settingsStore. storeSettings ( settings) { }
845+ settingsStore. storeSettings ( settings) { }
837846 }
838847
839848 // Actions
@@ -848,6 +857,8 @@ extension LoopDataManager {
848857 self . logger. default ( " Loop running " )
849858 NotificationCenter . default. post ( name: . LoopRunning, object: self )
850859
860+ self . storeUpdatedSettings ( )
861+
851862 self . lastLoopError = nil
852863 let startDate = self . now ( )
853864
@@ -1910,6 +1921,37 @@ extension LoopDataManager {
19101921 }
19111922}
19121923
1924+ extension LoopDataManager {
1925+ func didBecomeActive ( ) {
1926+ storeUpdatedSettings ( )
1927+ }
1928+
1929+ func storeUpdatedSettings( ) {
1930+ UNUserNotificationCenter . current ( ) . getNotificationSettings ( ) { notificationSettings in
1931+ self . dataAccessQueue. async {
1932+ guard let latestSettings = self . settingsStore. latestSettings else {
1933+ return
1934+ }
1935+
1936+ let notificationSettings = NotificationSettings ( notificationSettings)
1937+ let controllerDevice = UIDevice . current. controllerDevice
1938+ let cgmDevice = self . delegate? . cgmManagerStatus? . device
1939+ let pumpDevice = self . delegate? . pumpManagerStatus? . device
1940+
1941+ if notificationSettings != latestSettings. notificationSettings ||
1942+ controllerDevice != latestSettings. controllerDevice ||
1943+ cgmDevice != latestSettings. cgmDevice ||
1944+ pumpDevice != latestSettings. pumpDevice
1945+ {
1946+ self . storeSettings ( notificationSettings: notificationSettings,
1947+ controllerDevice: controllerDevice,
1948+ cgmDevice: cgmDevice,
1949+ pumpDevice: pumpDevice)
1950+ }
1951+ }
1952+ }
1953+ }
1954+ }
19131955
19141956extension LoopDataManager {
19151957 /// Generates a diagnostic report about the current state
@@ -2045,6 +2087,9 @@ protocol LoopDataManagerDelegate: AnyObject {
20452087
20462088 /// The pump manager status, if one exists.
20472089 var pumpManagerStatus : PumpManagerStatus ? { get }
2090+
2091+ /// The cgm manager status, if one exists.
2092+ var cgmManagerStatus : CGMManagerStatus ? { get }
20482093}
20492094
20502095private extension TemporaryScheduleOverride {
0 commit comments