From 79fc75edbde251bd172d8282727141aafec9700c Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Tue, 23 Jan 2024 16:50:55 -0600 Subject: [PATCH] Fixes not updating featured apps installation status on source detail page --- .../SourceDetailContentViewController.swift | 20 ++++++++++++ .../Sources/SourceDetailViewController.swift | 31 ------------------- 2 files changed, 20 insertions(+), 31 deletions(-) diff --git a/AltStore/Sources/SourceDetailContentViewController.swift b/AltStore/Sources/SourceDetailContentViewController.swift index d8af74c6..8427d45f 100644 --- a/AltStore/Sources/SourceDetailContentViewController.swift +++ b/AltStore/Sources/SourceDetailContentViewController.swift @@ -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 ?? [] + let refreshedObjects = notification.userInfo?[NSRefreshedObjectsKey] as? Set ?? [] + + 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 diff --git a/AltStore/Sources/SourceDetailViewController.swift b/AltStore/Sources/SourceDetailViewController.swift index d6dab7f1..7549b269 100644 --- a/AltStore/Sources/SourceDetailViewController.swift +++ b/AltStore/Sources/SourceDetailViewController.swift @@ -84,38 +84,7 @@ class SourceDetailViewController: HeaderContentViewController