From 8fb0e55712a82e7331a7404f45e47a1bfc09b3fe Mon Sep 17 00:00:00 2001 From: mpangburn Date: Wed, 29 Jan 2020 19:30:05 -0800 Subject: [PATCH] Support enacting manual loop if loop error --- .../StatusTableViewController.swift | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Loop/View Controllers/StatusTableViewController.swift b/Loop/View Controllers/StatusTableViewController.swift index 0eb5becb43..a64fe01f43 100644 --- a/Loop/View Controllers/StatusTableViewController.swift +++ b/Loop/View Controllers/StatusTableViewController.swift @@ -1258,13 +1258,23 @@ final class StatusTableViewController: ChartsTableViewController { } @objc private func showLastError(_: Any) { + var error: Error? = nil // First, check whether we have a device error after the most recent completion date if let deviceError = deviceManager.lastError, deviceError.date > (hudView?.loopCompletionHUD.lastLoopCompleted ?? .distantPast) { - self.present(UIAlertController(with: deviceError.error), animated: true) + error = deviceError.error } else if let lastLoopError = lastLoopError { - self.present(UIAlertController(with: lastLoopError), animated: true) + error = lastLoopError + } + + if error != nil { + let alertController = UIAlertController(with: error!) + let manualLoopAction = UIAlertAction(title: NSLocalizedString("Retry", comment: "The button text for attempting a manual loop"), style: .default, handler: { _ in + self.deviceManager.loopManager.loop() + }) + alertController.addAction(manualLoopAction) + present(alertController, animated: true) } }