Presents confirmation alert before refreshing AltStore

This commit is contained in:
Riley Testut
2019-06-25 14:35:00 -07:00
parent 84f564452b
commit 5d59407eeb

View File

@@ -130,68 +130,85 @@ private extension MyAppsViewController
func refresh(_ installedApps: [InstalledApp], completionHandler: @escaping (Result<[String : Result<InstalledApp, Error>], Error>) -> Void) func refresh(_ installedApps: [InstalledApp], completionHandler: @escaping (Result<[String : Result<InstalledApp, Error>], Error>) -> Void)
{ {
if self.refreshGroup == nil func refresh()
{ {
let toastView = RSTToastView(text: "Refreshing...", detailText: nil) if self.refreshGroup == nil
toastView.tintColor = .altPurple {
toastView.activityIndicatorView.startAnimating() let toastView = RSTToastView(text: "Refreshing...", detailText: nil)
toastView.show(in: self.navigationController?.view ?? self.view) toastView.tintColor = .altPurple
} toastView.activityIndicatorView.startAnimating()
toastView.show(in: self.navigationController?.view ?? self.view)
let group = AppManager.shared.refresh(installedApps, presentingViewController: self, group: self.refreshGroup) }
group.completionHandler = { (result) in
DispatchQueue.main.async { let group = AppManager.shared.refresh(installedApps, presentingViewController: self, group: self.refreshGroup)
switch result group.completionHandler = { (result) in
{ DispatchQueue.main.async {
case .failure(let error): switch result
let toastView = RSTToastView(text: error.localizedDescription, detailText: nil)
toastView.tintColor = .red
toastView.show(in: self.navigationController?.view ?? self.view, duration: 2.0)
self.refreshErrors = [:]
case .success(let results):
let failures = results.compactMapValues { $0.error }
if failures.isEmpty
{ {
let toastView = RSTToastView(text: NSLocalizedString("Successfully refreshed apps!", comment: ""), detailText: nil) case .failure(let error):
toastView.tintColor = .altPurple let toastView = RSTToastView(text: error.localizedDescription, detailText: nil)
toastView.tintColor = .red
toastView.show(in: self.navigationController?.view ?? self.view, duration: 2.0) toastView.show(in: self.navigationController?.view ?? self.view, duration: 2.0)
}
else self.refreshErrors = [:]
{
let localizedText: String case .success(let results):
if failures.count == 1 let failures = results.compactMapValues { $0.error }
if failures.isEmpty
{ {
localizedText = String(format: NSLocalizedString("Failed to refresh %@ app.", comment: ""), NSNumber(value: failures.count)) let toastView = RSTToastView(text: NSLocalizedString("Successfully refreshed apps!", comment: ""), detailText: nil)
toastView.tintColor = .altPurple
toastView.show(in: self.navigationController?.view ?? self.view, duration: 2.0)
} }
else else
{ {
localizedText = String(format: NSLocalizedString("Failed to refresh %@ apps.", comment: ""), NSNumber(value: failures.count)) let localizedText: String
if failures.count == 1
{
localizedText = String(format: NSLocalizedString("Failed to refresh %@ app.", comment: ""), NSNumber(value: failures.count))
}
else
{
localizedText = String(format: NSLocalizedString("Failed to refresh %@ apps.", comment: ""), NSNumber(value: failures.count))
}
let toastView = RSTToastView(text: localizedText, detailText: nil)
toastView.tintColor = .red
toastView.show(in: self.navigationController?.view ?? self.view, duration: 2.0)
} }
let toastView = RSTToastView(text: localizedText, detailText: nil) self.refreshErrors = failures
toastView.tintColor = .red
toastView.show(in: self.navigationController?.view ?? self.view, duration: 2.0)
} }
self.refreshErrors = failures self.progressView.observedProgress = nil
self.progressView.progress = 0.0
self.update()
self.refreshGroup = nil
completionHandler(result)
} }
self.progressView.observedProgress = nil
self.progressView.progress = 0.0
self.update()
self.refreshGroup = nil
completionHandler(result)
} }
self.progressView.observedProgress = group.progress
self.refreshGroup = group
} }
self.progressView.observedProgress = group.progress if installedApps.contains(where: { $0.app.identifier == App.altstoreAppID })
{
self.refreshGroup = group let alertController = UIAlertController(title: NSLocalizedString("Refresh AltStore?", comment: ""), message: NSLocalizedString("AltStore will quit when it is finished refreshing.", comment: ""), preferredStyle: .alert)
alertController.addAction(.cancel)
alertController.addAction(UIAlertAction(title: NSLocalizedString("Refresh", comment: ""), style: .default) { (action) in
refresh()
})
self.present(alertController, animated: true, completion: nil)
}
else
{
refresh()
}
} }
} }