mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
Adds pull-to-refresh to check for updates
This commit is contained in:
@@ -54,6 +54,7 @@ final class MyAppsViewController: UICollectionViewController
|
|||||||
private var refreshGroup: RefreshGroup?
|
private var refreshGroup: RefreshGroup?
|
||||||
private var sideloadingProgress: Progress?
|
private var sideloadingProgress: Progress?
|
||||||
private var dropDestinationIndexPath: IndexPath?
|
private var dropDestinationIndexPath: IndexPath?
|
||||||
|
private var isCheckingForUpdates = false
|
||||||
|
|
||||||
private var _imagePickerInstalledApp: InstalledApp?
|
private var _imagePickerInstalledApp: InstalledApp?
|
||||||
|
|
||||||
@@ -97,6 +98,10 @@ final class MyAppsViewController: UICollectionViewController
|
|||||||
self.collectionView.register(InstalledAppsCollectionHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "ActiveAppsHeader")
|
self.collectionView.register(InstalledAppsCollectionHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "ActiveAppsHeader")
|
||||||
self.collectionView.register(InstalledAppsCollectionHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "InactiveAppsHeader")
|
self.collectionView.register(InstalledAppsCollectionHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "InactiveAppsHeader")
|
||||||
|
|
||||||
|
let refreshControl = UIRefreshControl()
|
||||||
|
refreshControl.addTarget(self, action: #selector(MyAppsViewController.checkForUpdates(_:)), for: .primaryActionTriggered)
|
||||||
|
self.collectionView.refreshControl = refreshControl
|
||||||
|
|
||||||
self.sideloadingProgressView = UIProgressView(progressViewStyle: .bar)
|
self.sideloadingProgressView = UIProgressView(progressViewStyle: .bar)
|
||||||
self.sideloadingProgressView.translatesAutoresizingMaskIntoConstraints = false
|
self.sideloadingProgressView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
self.sideloadingProgressView.progressTintColor = .altPrimary
|
self.sideloadingProgressView.progressTintColor = .altPrimary
|
||||||
@@ -1441,6 +1446,44 @@ private extension MyAppsViewController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func checkForUpdates(_ sender: UIRefreshControl)
|
||||||
|
{
|
||||||
|
guard !self.isCheckingForUpdates else { return }
|
||||||
|
self.isCheckingForUpdates = true
|
||||||
|
|
||||||
|
AppManager.shared.fetchSources() { (result) in
|
||||||
|
do
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
defer {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.isCheckingForUpdates = false
|
||||||
|
sender.endRefreshing()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let (_, context) = try result.get()
|
||||||
|
try context.save()
|
||||||
|
|
||||||
|
}
|
||||||
|
catch let error as AppManager.FetchSourcesError
|
||||||
|
{
|
||||||
|
try error.managedObjectContext?.save()
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch let error as NSError
|
||||||
|
{
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
let toastView = ToastView(error: error.withLocalizedTitle(NSLocalizedString("Failed to Check for Updates", comment: "")))
|
||||||
|
toastView.addTarget(nil, action: #selector(TabBarController.presentSources), for: .touchUpInside)
|
||||||
|
toastView.show(in: self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension MyAppsViewController
|
extension MyAppsViewController
|
||||||
|
|||||||
Reference in New Issue
Block a user