Skip to content

Commit

Permalink
Merge pull request nightscout#376 from dnzxy/fix/trio-g7-statemanagement
Browse files Browse the repository at this point in the history
Fix G7 plist File State Management
  • Loading branch information
Sjoerd-Bo3 authored and mountrcg committed Sep 11, 2024
1 parent b593934 commit c3eb39d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
31 changes: 25 additions & 6 deletions FreeAPS/Sources/APS/CGM/PluginSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,24 @@ extension PluginSource: CGMManagerDelegate {
return glucoseStorage.lastGlucoseDate()
}

func cgmManagerDidUpdateState(_: CGMManager) {
func cgmManagerDidUpdateState(_ cgmManager: CGMManager) {
dispatchPrecondition(condition: .onQueue(processQueue))
// guard let g6Manager = manager as? TransmitterManager else {
// return
// }
// glucoseManager?.settingsManager.settings.uploadGlucose = g6Manager.shouldSyncToRemoteService
// UserDefaults.standard.dexcomTransmitterID = g6Manager.rawState["transmitterID"] as? String

guard let fetchGlucoseManager = glucoseManager else {
debug(
.deviceManager,
"Could not gracefully unwrap FetchGlucoseManager upon observing LoopKit's cgmManagerDidUpdateState"
)
return
}
// Adjust app-specific NS Upload setting value when CGM setting is changed
fetchGlucoseManager.settingsManager.settings.uploadGlucose = cgmManager.shouldSyncToRemoteService

fetchGlucoseManager.updateGlucoseSource(
cgmGlucoseSourceType: fetchGlucoseManager.settingsManager.settings.cgm,
cgmGlucosePluginId: fetchGlucoseManager.settingsManager.settings.cgmPluginIdentifier,
newManager: cgmManager as? CGMManagerUI
)
}

func credentialStoragePrefix(for _: CGMManager) -> String {
Expand All @@ -160,6 +171,14 @@ extension PluginSource: CGMManagerDelegate {

private func readCGMResult(readingResult: CGMReadingResult) -> Result<[BloodGlucose], Error> {
debug(.deviceManager, "PLUGIN CGM - Process CGM Reading Result launched with \(readingResult)")

if glucoseManager?.glucoseSource == nil {
debug(
.deviceManager,
"No glucose source available."
)
}

switch readingResult {
case let .newData(values):

Expand Down
34 changes: 18 additions & 16 deletions FreeAPS/Sources/APS/FetchGlucoseManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ final class BaseFetchGlucoseManager: FetchGlucoseManager, Injectable {
if self.cgmGlucoseSourceType != cgmGlucoseSourceType || self.cgmGlucosePluginId != cgmGlucosePluginId {
removeCalibrations()
cgmManager = nil
glucoseSource = nil
}

self.cgmGlucoseSourceType = cgmGlucoseSourceType
Expand All @@ -123,23 +124,24 @@ final class BaseFetchGlucoseManager: FetchGlucoseManager, Injectable {
saveConfigManager()
}

switch self.cgmGlucoseSourceType {
case .none:
glucoseSource = nil
case .xdrip:
glucoseSource = AppGroupSource(from: "xDrip", cgmType: .xdrip)
case .nightscout:
glucoseSource = nightscoutManager
case .simulator:
glucoseSource = simulatorSource
case .glucoseDirect:
glucoseSource = AppGroupSource(from: "GlucoseDirect", cgmType: .glucoseDirect)
case .enlite:
glucoseSource = deviceDataManager
case .plugin:
glucoseSource = PluginSource(glucoseStorage: glucoseStorage, glucoseManager: self)
if glucoseSource == nil {
switch self.cgmGlucoseSourceType {
case .none:
glucoseSource = nil
case .xdrip:
glucoseSource = AppGroupSource(from: "xDrip", cgmType: .xdrip)
case .nightscout:
glucoseSource = nightscoutManager
case .simulator:
glucoseSource = simulatorSource
case .glucoseDirect:
glucoseSource = AppGroupSource(from: "GlucoseDirect", cgmType: .glucoseDirect)
case .enlite:
glucoseSource = deviceDataManager
case .plugin:
glucoseSource = PluginSource(glucoseStorage: glucoseStorage, glucoseManager: self)
}
}
// update the config
}

/// Upload cgmManager from raw value
Expand Down

0 comments on commit c3eb39d

Please sign in to comment.