don't sync treatments when running in background

there's no need to sync the treatments if the app is running in the background
This commit is contained in:
Johan Degraeve 2024-02-25 14:30:22 +01:00
parent cdb3dc565d
commit 7acb5734ff
1 changed files with 3 additions and 10 deletions

View File

@ -170,16 +170,9 @@ public class NightScoutUploadManager: NSObject, ObservableObject {
// and nightScoutUrl exists
guard UserDefaults.standard.nightScoutEnabled, UserDefaults.standard.nightScoutUrl != nil else {return}
// if schedule is on, check if Nightscout is enabled according to schedule
// if app is in foreground then overrule this setting - if the app is in the foreground, then probably it's not the aim to save battery (which is the reason why the schedule is useful) - and if the app is in the foreground, user probably wants to see treatments added by other app (eg Loop), even if nightScout schedule says to not schedule
if UserDefaults.standard.nightScoutUseSchedule && !UserDefaults.standard.appInForeGround {
if let schedule = UserDefaults.standard.nightScoutSchedule {
if !schedule.indicatesOn(forWhen: Date()) {
return
}
}
}
// no sync needed if app is running in the background
guard UserDefaults.standard.appInForeGround else {return}
// if sync already running, then set nightScoutTreatmentSyncRequired to true
// sync is running already, once stopped it will rerun
if let nightScoutTreatmentsSyncStartTimeStamp = nightScoutTreatmentsSyncStartTimeStamp {