Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix G7 plist File State Management #376

Merged
merged 9 commits into from
Aug 11, 2024
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
11 changes: 7 additions & 4 deletions scripts/capture-build-details.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,24 @@ else
# Capture the current date and write it to BuildDetails.plist
plutil -replace com-trio-build-date -string "$(date)" "${info_plist_path}"

# Retrieve the current branch
git_branch=$(git symbolic-ref --short -q HEAD)
# Retrieve the current branch, if available
git_branch=$(git symbolic-ref --short -q HEAD || echo "")

# Attempt to retrieve the current tag
git_tag=$(git describe --tags --exact-match 2>/dev/null || echo "")

# Retrieve the current SHA of the latest commit
git_commit_sha=$(git log -1 --format="%h" --abbrev=7)

# Determine the branch or tag information
# Determine the branch or tag information, or fallback to SHA if in detached state
git_branch_or_tag="${git_branch:-${git_tag}}"
if [ -z "${git_branch_or_tag}" ]; then
git_branch_or_tag="detached"
fi

# Update BuildDetails.plist with the branch or tag information
plutil -replace com-trio-branch -string "${git_branch_or_tag}" "${info_plist_path}"

# Update BuildDetails.plist with the SHA information
plutil -replace com-trio-commit-sha -string "${git_commit_sha}" "${info_plist_path}"
fi
fi