Skip to content

Commit

Permalink
LOOP-4960 Upload settings on restart (#697)
Browse files Browse the repository at this point in the history
* Upload settings on restart

* Comments from review
  • Loading branch information
ps2 authored Aug 23, 2024
1 parent 4e3a0d6 commit 4775711
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
6 changes: 3 additions & 3 deletions Loop/Managers/DeviceDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1263,11 +1263,11 @@ struct CancelTempBasalFailedMaximumBasalRateChangedError: LocalizedError {
//MARK: - RemoteDataServicesManagerDelegate protocol conformance

extension DeviceDataManager : RemoteDataServicesManagerDelegate {
var shouldSyncToRemoteService: Bool {
var shouldSyncGlucoseToRemoteService: Bool {
guard let cgmManager = cgmManager else {
return onboardingManager?.isComplete == true
return true
}
return cgmManager.shouldSyncToRemoteService && (onboardingManager?.isComplete == true)
return cgmManager.shouldSyncToRemoteService
}
}

Expand Down
2 changes: 2 additions & 0 deletions Loop/Managers/LoopAppManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ class LoopAppManager: NSObject {

settingsManager.remoteDataServicesManager = remoteDataServicesManager

remoteDataServicesManager.triggerAllUploads()

servicesManager = ServicesManager(
pluginManager: pluginManager,
alertManager: alertManager,
Expand Down
3 changes: 2 additions & 1 deletion Loop/Managers/LoopDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ final class LoopDataManager: ObservableObject {

var dosingDecision = StoredDosingDecision(
date: loopBaseTime,
reason: "loop"
reason: "loop",
settings: StoredDosingDecision.Settings(settingsProvider.settings)
)

do {
Expand Down
26 changes: 11 additions & 15 deletions Loop/Managers/RemoteDataServicesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,15 @@ final class RemoteDataServicesManager {
}
}
}


func triggerAllUploads() {
Task {
for type in RemoteDataType.allCases {
await performUpload(for: type)
}
}
}

func triggerUpload(for triggeringType: RemoteDataType) {
Task {
await performUpload(for: triggeringType)
Expand Down Expand Up @@ -241,8 +249,6 @@ final class RemoteDataServicesManager {

extension RemoteDataServicesManager {
private func uploadAlertData(to remoteDataService: RemoteDataService) {
guard delegate?.shouldSyncToRemoteService == true else { return }

uploadGroup.enter()

let key = UploadTaskKey(serviceIdentifier: remoteDataService.pluginIdentifier, remoteDataType: .alert)
Expand Down Expand Up @@ -278,8 +284,6 @@ extension RemoteDataServicesManager {

extension RemoteDataServicesManager {
private func uploadCarbData(to remoteDataService: RemoteDataService) {
guard delegate?.shouldSyncToRemoteService == true else { return }

uploadGroup.enter()

let key = UploadTaskKey(serviceIdentifier: remoteDataService.pluginIdentifier, remoteDataType: .carb)
Expand Down Expand Up @@ -322,8 +326,6 @@ extension RemoteDataServicesManager {

extension RemoteDataServicesManager {
private func uploadDoseData(to remoteDataService: RemoteDataService) {
guard delegate?.shouldSyncToRemoteService == true else { return }

uploadGroup.enter()

let key = UploadTaskKey(serviceIdentifier: remoteDataService.pluginIdentifier, remoteDataType: .dose)
Expand Down Expand Up @@ -366,8 +368,6 @@ extension RemoteDataServicesManager {

extension RemoteDataServicesManager {
private func uploadDosingDecisionData(to remoteDataService: RemoteDataService) {
guard delegate?.shouldSyncToRemoteService == true else { return }

uploadGroup.enter()

let key = UploadTaskKey(serviceIdentifier: remoteDataService.pluginIdentifier, remoteDataType: .dosingDecision)
Expand Down Expand Up @@ -411,7 +411,7 @@ extension RemoteDataServicesManager {

extension RemoteDataServicesManager {
private func uploadGlucoseData(to remoteDataService: RemoteDataService) {
guard delegate?.shouldSyncToRemoteService == true else { return }
guard delegate?.shouldSyncGlucoseToRemoteService != false else { return }

uploadGroup.enter()

Expand Down Expand Up @@ -455,8 +455,6 @@ extension RemoteDataServicesManager {

extension RemoteDataServicesManager {
private func uploadPumpEventData(to remoteDataService: RemoteDataService) {
guard delegate?.shouldSyncToRemoteService == true else { return }

uploadGroup.enter()

let key = UploadTaskKey(serviceIdentifier: remoteDataService.pluginIdentifier, remoteDataType: .pumpEvent)
Expand Down Expand Up @@ -499,8 +497,6 @@ extension RemoteDataServicesManager {

extension RemoteDataServicesManager {
private func uploadSettingsData(to remoteDataService: RemoteDataService) {
guard delegate?.shouldSyncToRemoteService == true else { return }

uploadGroup.enter()

let key = UploadTaskKey(serviceIdentifier: remoteDataService.pluginIdentifier, remoteDataType: .settings)
Expand Down Expand Up @@ -653,7 +649,7 @@ extension RemoteDataServicesManager {
extension RemoteDataServicesManager: UploadEventListener { }

protocol RemoteDataServicesManagerDelegate: AnyObject {
var shouldSyncToRemoteService: Bool { get }
var shouldSyncGlucoseToRemoteService: Bool { get }
}


Expand Down

0 comments on commit 4775711

Please sign in to comment.