Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions Loop/Managers/LoopDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ final class LoopDataManager {

self.trustedTimeOffset = trustedTimeOffset

retrospectiveCorrection = settings.enabledRetrospectiveCorrectionAlgorithm

overrideIntentObserver = UserDefaults.appGroup?.observe(\.intentExtensionOverrideToSet, options: [.new], changeHandler: {[weak self] (defaults, change) in
guard let name = change.newValue??.lowercased(), let appGroup = UserDefaults.appGroup else {
return
Expand Down Expand Up @@ -435,7 +433,23 @@ final class LoopDataManager {
}

// Confined to dataAccessQueue
private var retrospectiveCorrection: RetrospectiveCorrection
private var lastIntegralRetrospectiveCorrectionEnabled: Bool?
private var cachedRetrospectiveCorrection: RetrospectiveCorrection?

var retrospectiveCorrection: RetrospectiveCorrection {
let currentIntegralRetrospectiveCorrectionEnabled = UserDefaults.standard.integralRetrospectiveCorrectionEnabled

if lastIntegralRetrospectiveCorrectionEnabled != currentIntegralRetrospectiveCorrectionEnabled || cachedRetrospectiveCorrection == nil {
lastIntegralRetrospectiveCorrectionEnabled = currentIntegralRetrospectiveCorrectionEnabled
if currentIntegralRetrospectiveCorrectionEnabled {
cachedRetrospectiveCorrection = IntegralRetrospectiveCorrection(effectDuration: LoopSettings.retrospectiveCorrectionEffectDuration)
} else {
cachedRetrospectiveCorrection = StandardRetrospectiveCorrection(effectDuration: LoopSettings.retrospectiveCorrectionEffectDuration)
}
}

return cachedRetrospectiveCorrection!
}

// MARK: - Background task management

Expand Down
15 changes: 0 additions & 15 deletions Loop/Models/LoopSettings+Loop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,4 @@ extension LoopSettings {

static let retrospectiveCorrectionEffectDuration = TimeInterval(hours: 1)

/// Creates an instance of the enabled retrospective correction implementation
var enabledRetrospectiveCorrectionAlgorithm: RetrospectiveCorrection {
var enabledRetrospectiveCorrectionAlgorithm: RetrospectiveCorrection

let isIntegralRetrospectiveCorrectionEnabled = UserDefaults.standard.integralRetrospectiveCorrectionEnabled

if isIntegralRetrospectiveCorrectionEnabled {
enabledRetrospectiveCorrectionAlgorithm = IntegralRetrospectiveCorrection(effectDuration: LoopSettings.retrospectiveCorrectionEffectDuration)
} else {
enabledRetrospectiveCorrectionAlgorithm = StandardRetrospectiveCorrection(effectDuration: LoopSettings.retrospectiveCorrectionEffectDuration)
}

return enabledRetrospectiveCorrectionAlgorithm
}

}