mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-13 16:53:29 +01:00
[AltStore] Refresh all apps from My Apps tab
This commit is contained in:
@@ -11,6 +11,8 @@ import Roxas
|
||||
|
||||
class MyAppsViewController: UITableViewController
|
||||
{
|
||||
private var refreshErrors = [String: Error]()
|
||||
|
||||
private lazy var dataSource = self.makeDataSource()
|
||||
|
||||
private lazy var dateFormatter: DateFormatter = {
|
||||
@@ -25,6 +27,15 @@ class MyAppsViewController: UITableViewController
|
||||
super.viewDidLoad()
|
||||
|
||||
self.tableView.dataSource = self.dataSource
|
||||
|
||||
self.update()
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool)
|
||||
{
|
||||
super.viewWillAppear(animated)
|
||||
|
||||
self.update()
|
||||
}
|
||||
|
||||
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
|
||||
@@ -52,23 +63,94 @@ private extension MyAppsViewController
|
||||
|
||||
let dataSource = RSTFetchedResultsTableViewDataSource(fetchRequest: fetchRequest, managedObjectContext: DatabaseManager.shared.viewContext)
|
||||
dataSource.proxy = self
|
||||
dataSource.cellConfigurationHandler = { (cell, installedApp, indexPath) in
|
||||
dataSource.cellConfigurationHandler = { [weak self] (cell, installedApp, indexPath) in
|
||||
guard let app = installedApp.app else { return }
|
||||
|
||||
cell.textLabel?.text = app.name
|
||||
|
||||
let detailText =
|
||||
"""
|
||||
Expires: \(self.dateFormatter.string(from: installedApp.expirationDate))
|
||||
Expires: \(self?.dateFormatter.string(from: installedApp.expirationDate) ?? "-")
|
||||
"""
|
||||
|
||||
cell.detailTextLabel?.numberOfLines = 1
|
||||
cell.detailTextLabel?.text = detailText
|
||||
cell.detailTextLabel?.textColor = .red
|
||||
|
||||
if let _ = self?.refreshErrors[installedApp.bundleIdentifier]
|
||||
{
|
||||
cell.accessoryType = .detailButton
|
||||
cell.tintColor = .red
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.accessoryType = .none
|
||||
cell.tintColor = nil
|
||||
}
|
||||
}
|
||||
|
||||
return dataSource
|
||||
}
|
||||
|
||||
func update()
|
||||
{
|
||||
self.navigationItem.rightBarButtonItem?.isEnabled = !(self.dataSource.fetchedResultsController.fetchedObjects?.isEmpty ?? true)
|
||||
|
||||
self.tableView.reloadData()
|
||||
}
|
||||
}
|
||||
|
||||
private extension MyAppsViewController
|
||||
{
|
||||
@IBAction func refreshAllApps(_ sender: UIBarButtonItem)
|
||||
{
|
||||
sender.isIndicatingActivity = true
|
||||
|
||||
AppManager.shared.refreshAllApps(presentingViewController: self) { (result) in
|
||||
DispatchQueue.main.async {
|
||||
switch result
|
||||
{
|
||||
case .failure(let error):
|
||||
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)
|
||||
toastView.tintColor = .altPurple
|
||||
toastView.show(in: self.navigationController?.view ?? self.view, duration: 2.0)
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
}
|
||||
|
||||
self.refreshErrors = failures
|
||||
}
|
||||
|
||||
sender.isIndicatingActivity = false
|
||||
self.update()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension MyAppsViewController
|
||||
@@ -101,7 +183,7 @@ extension MyAppsViewController
|
||||
toastView.activityIndicatorView.startAnimating()
|
||||
toastView.show(in: self.navigationController?.view ?? self.view)
|
||||
|
||||
AppManager.shared.refresh(installedApp) { (result) in
|
||||
AppManager.shared.refresh(installedApp, presentingViewController: self) { (result) in
|
||||
do
|
||||
{
|
||||
let app = try result.get()
|
||||
@@ -111,6 +193,8 @@ extension MyAppsViewController
|
||||
let toastView = RSTToastView(text: "Refreshed \(installedApp.app.name)!", detailText: nil)
|
||||
toastView.tintColor = .altPurple
|
||||
toastView.show(in: self.navigationController?.view ?? self.view, duration: 2)
|
||||
|
||||
self.update()
|
||||
}
|
||||
}
|
||||
catch
|
||||
@@ -119,6 +203,8 @@ extension MyAppsViewController
|
||||
let toastView = RSTToastView(text: "Failed to refresh \(installedApp.app.name)", detailText: error.localizedDescription)
|
||||
toastView.tintColor = .altPurple
|
||||
toastView.show(in: self.navigationController?.view ?? self.view, duration: 2)
|
||||
|
||||
self.update()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,4 +216,15 @@ extension MyAppsViewController
|
||||
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath)
|
||||
{
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath)
|
||||
{
|
||||
let installedApp = self.dataSource.item(at: indexPath)
|
||||
|
||||
guard let error = self.refreshErrors[installedApp.bundleIdentifier] else { return }
|
||||
|
||||
let alertController = UIAlertController(title: "Failed to Refresh \(installedApp.app.name)", message: error.localizedDescription, preferredStyle: .alert)
|
||||
alertController.addAction(.ok)
|
||||
self.present(alertController, animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user