Skip to content

Commit 58ed7ed

Browse files
authored
[LOOP-4597] updated handling of pump deactivation as apart of reset (#562)
1 parent e7e6fe6 commit 58ed7ed

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

Loop/Managers/Alerts/AlertManager.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -778,16 +778,24 @@ extension AlertManager: AlertPermissionsCheckerDelegate {
778778
}
779779

780780
extension AlertManager {
781-
func presentConfirmCrashAlert(confirmAction: @escaping () -> Void) {
781+
func presentConfirmCrashAlert(confirmAction: @escaping (@escaping () -> Void) -> Void) {
782782
let alert = UIAlertController(title: "New Study Product Detected", message: "We've detected a new study product is selected. In order to show use this study product, Tidepool Loop will need to restart.", preferredStyle: .alert)
783783
alert.addAction(UIAlertAction(title: "Confirm", style: .default, handler: { _ in
784-
confirmAction()
785-
fatalError("DEBUG: Resetting Loop")
784+
confirmAction() {
785+
fatalError("DEBUG: Resetting Loop")
786+
}
786787
}))
787788
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
788789

789790
alertPresenter.present(alert, animated: true)
790791
}
792+
793+
func presentCouldNotResetLoopAlert(error: Error) {
794+
let alert = UIAlertController(title: "Could Not Restart Tidepool Loop", message: "While trying to restart Tidepool Loop an error occured.\n\n\(error.localizedDescription)", preferredStyle: .alert)
795+
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
796+
797+
alertPresenter.present(alert, animated: true)
798+
}
791799
}
792800

793801
fileprivate extension UserDefaults {

Loop/Managers/LoopAppManager.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,21 @@ class LoopAppManager: NSObject {
374374
deviceDataManager.pluginManager.availableSupports.forEach { supportUI in
375375
if supportUI.loopNeedsReset {
376376
supportUI.loopNeedsReset = false
377-
alertManager.presentConfirmCrashAlert() { [weak self] in
378-
self?.deviceDataManager.pumpManager?.prepareForDeactivation({ _ in })
379-
supportUI.resetLoop()
377+
alertManager.presentConfirmCrashAlert() { [weak self] completion in
378+
guard let pumpManager = self?.deviceDataManager.pumpManager else {
379+
supportUI.resetLoop()
380+
completion()
381+
return
382+
}
383+
384+
pumpManager.prepareForDeactivation() { [weak self] error in
385+
guard let error = error else {
386+
supportUI.resetLoop()
387+
completion()
388+
return
389+
}
390+
self?.alertManager.presentCouldNotResetLoopAlert(error: error)
391+
}
380392
}
381393
}
382394
}

0 commit comments

Comments
 (0)