Skip to content

Commit c4c3556

Browse files
committed
Fixed a bug in fast battery drop to ignore an initial condition of 100%
1 parent c2a72e4 commit c4c3556

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

LoopFollow/Controllers/Alarms.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -518,12 +518,15 @@ extension MainViewController {
518518
if let previousBatteryLevel = deviceBatteryData.min(by: {
519519
abs($0.timestamp.timeIntervalSince(targetDate)) < abs($1.timestamp.timeIntervalSince(targetDate))
520520
}) {
521-
if (previousBatteryLevel.batteryLevel - currentBatteryLevel) >= dropPercentage {
522-
AlarmSound.whichAlarm = "Battery Drop"
521+
// ignore a drop with a previous level of 100 as it will trigger a false alarm
522+
if (previousBatteryLevel.batteryLevel < 100) {
523+
if (previousBatteryLevel.batteryLevel - currentBatteryLevel) >= dropPercentage {
524+
AlarmSound.whichAlarm = "Battery Drop"
523525

524-
if UserDefaultsRepository.alertBatteryDropRepeat.value { numLoops = -1 }
525-
triggerAlarm(sound: UserDefaultsRepository.alertBatteryDropSound.value, snooozedBGReadingTime: nil, overrideVolume: UserDefaultsRepository.overrideSystemOutputVolume.value, numLoops: numLoops, snoozeTime: UserDefaultsRepository.alertBatteryDropSnoozeHours.value, snoozeIncrement: 1, audio: true)
526-
return
526+
if UserDefaultsRepository.alertBatteryDropRepeat.value { numLoops = -1 }
527+
triggerAlarm(sound: UserDefaultsRepository.alertBatteryDropSound.value, snooozedBGReadingTime: nil, overrideVolume: UserDefaultsRepository.overrideSystemOutputVolume.value, numLoops: numLoops, snoozeTime: UserDefaultsRepository.alertBatteryDropSnoozeHours.value, snoozeIncrement: 1, audio: true)
528+
return
529+
}
527530
}
528531
}
529532
}

0 commit comments

Comments
 (0)