mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-11 07:43:28 +01:00
Fixes not updating featured apps installation status on source detail page
This commit is contained in:
@@ -72,6 +72,9 @@ class SourceDetailContentViewController: UICollectionViewController
|
||||
self.dataSource.proxy = self
|
||||
self.collectionView.dataSource = self.dataSource
|
||||
self.collectionView.prefetchDataSource = self.dataSource
|
||||
|
||||
let context = self.source.managedObjectContext ?? DatabaseManager.shared.viewContext
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(SourceDetailContentViewController.didChangeApps), name: NSManagedObjectContext.didChangeObjectsNotification, object: context)
|
||||
}
|
||||
|
||||
override func viewSafeAreaInsetsDidChange()
|
||||
@@ -451,6 +454,23 @@ private extension SourceDetailContentViewController
|
||||
{
|
||||
UIApplication.shared.open(installedApp.openAppURL)
|
||||
}
|
||||
|
||||
@objc func didChangeApps(_ notification: Notification)
|
||||
{
|
||||
// Make sure to include refreshed objects to catch all merged changes.
|
||||
let updatedObjects = notification.userInfo?[NSUpdatedObjectsKey] as? Set<NSManagedObject> ?? []
|
||||
let refreshedObjects = notification.userInfo?[NSRefreshedObjectsKey] as? Set<NSManagedObject> ?? []
|
||||
|
||||
let changedAppIndexes = updatedObjects.union(refreshedObjects).compactMap { $0 as? StoreApp }.compactMap { self.appsDataSource.items.firstIndex(of: $0) }
|
||||
let indexPaths = changedAppIndexes.map { IndexPath(item: $0, section: Section.featuredApps.rawValue) }
|
||||
|
||||
guard !indexPaths.isEmpty else { return }
|
||||
|
||||
// Async so that AppManager.installationProgress(for:) is nil when we update.
|
||||
DispatchQueue.main.async {
|
||||
self.collectionView.reloadItems(at: indexPaths)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension SourceDetailContentViewController: ScrollableContentViewController
|
||||
|
||||
Reference in New Issue
Block a user