diff --git a/AltStore/Managing Apps/AppManager.swift b/AltStore/Managing Apps/AppManager.swift index 3dd1ef9f..cf82b825 100644 --- a/AltStore/Managing Apps/AppManager.swift +++ b/AltStore/Managing Apps/AppManager.swift @@ -416,9 +416,9 @@ extension AppManager { completionHandler(.success((fetchedSources, managedObjectContext))) } + + NotificationCenter.default.post(name: AppManager.didFetchSourceNotification, object: self) } - - NotificationCenter.default.post(name: AppManager.didFetchSourceNotification, object: self) } self.run(operations, context: nil) diff --git a/AltStore/My Apps/MyAppsViewController.swift b/AltStore/My Apps/MyAppsViewController.swift index 5ad7b899..31efec73 100644 --- a/AltStore/My Apps/MyAppsViewController.swift +++ b/AltStore/My Apps/MyAppsViewController.swift @@ -194,7 +194,7 @@ private extension MyAppsViewController func makeUpdatesDataSource() -> RSTFetchedResultsCollectionViewPrefetchingDataSource { - let fetchRequest = InstalledApp.updatesFetchRequest() + let fetchRequest = InstalledApp.supportedUpdatesFetchRequest() fetchRequest.sortDescriptors = [NSSortDescriptor(keyPath: \InstalledApp.storeApp?.latestSupportedVersion?.date, ascending: false), NSSortDescriptor(keyPath: \InstalledApp.name, ascending: true)] fetchRequest.returnsObjectsAsFaults = false @@ -485,6 +485,15 @@ private extension MyAppsViewController { func update() { + do + { + try self.updatesDataSource.fetchedResultsController.performFetch() + } + catch + { + print("[ALTLog] Failed to fetch updates:", error) + } + if self.updatesDataSource.itemCount > 0 { self.navigationController?.tabBarItem.badgeValue = String(describing: self.updatesDataSource.itemCount) @@ -495,13 +504,6 @@ private extension MyAppsViewController self.navigationController?.tabBarItem.badgeValue = nil UIApplication.shared.applicationIconBadgeNumber = 0 } - - if self.isViewLoaded - { - UIView.performWithoutAnimation { - self.collectionView.reloadSections(IndexSet(integer: Section.updates.rawValue)) - } - } } func fetchAppIDs() diff --git a/AltStoreCore/Model/InstalledApp.swift b/AltStoreCore/Model/InstalledApp.swift index 9bbfc46d..b27c88e6 100644 --- a/AltStoreCore/Model/InstalledApp.swift +++ b/AltStoreCore/Model/InstalledApp.swift @@ -164,7 +164,21 @@ public extension InstalledApp { let fetchRequest = InstalledApp.fetchRequest() as NSFetchRequest fetchRequest.predicate = NSPredicate(format: "%K == YES AND %K != nil AND %K != %K", - #keyPath(InstalledApp.isActive), #keyPath(InstalledApp.storeApp), #keyPath(InstalledApp.version), #keyPath(InstalledApp.storeApp.latestSupportedVersion.version)) + #keyPath(InstalledApp.isActive), + #keyPath(InstalledApp.storeApp), + #keyPath(InstalledApp.version), #keyPath(InstalledApp.storeApp.latestVersionString)) + return fetchRequest + } + + class func supportedUpdatesFetchRequest() -> NSFetchRequest + { + let predicate = NSPredicate(format: "%K != nil AND %K != %K", + #keyPath(InstalledApp.storeApp.latestSupportedVersion), + #keyPath(InstalledApp.version), #keyPath(InstalledApp.storeApp.latestSupportedVersion.version)) + + let fetchRequest = InstalledApp.updatesFetchRequest() + fetchRequest.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [fetchRequest.predicate, predicate].compactMap { $0 }) + return fetchRequest } diff --git a/AltStoreCore/Model/Migrations/Policies/StoreApp10ToStoreApp11Policy.swift b/AltStoreCore/Model/Migrations/Policies/StoreApp10ToStoreApp11Policy.swift index 7ca75c60..aba473f8 100644 --- a/AltStoreCore/Model/Migrations/Policies/StoreApp10ToStoreApp11Policy.swift +++ b/AltStoreCore/Model/Migrations/Policies/StoreApp10ToStoreApp11Policy.swift @@ -22,7 +22,7 @@ fileprivate extension NSManagedObject } var storeAppVersion: String? { - let version = self.value(forKey: #keyPath(StoreApp._version)) as? String + let version = self.value(forKey: #keyPath(StoreApp.latestVersionString)) as? String return version } diff --git a/AltStoreCore/Model/StoreApp.swift b/AltStoreCore/Model/StoreApp.swift index f4c6be0e..6934cb13 100644 --- a/AltStoreCore/Model/StoreApp.swift +++ b/AltStoreCore/Model/StoreApp.swift @@ -106,9 +106,9 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable @NSManaged public private(set) var iconURL: URL @NSManaged public private(set) var screenshotURLs: [URL] - @NSManaged @objc(version) internal var _version: String - @NSManaged @objc(versionDate) internal var _versionDate: Date - @NSManaged @objc(versionDescription) internal var _versionDescription: String? + @NSManaged @objc(version) public private(set) var latestVersionString: String + @NSManaged @objc(versionDate) internal private(set) var _versionDate: Date + @NSManaged @objc(versionDescription) internal private(set) var _versionDescription: String? @NSManaged @objc(downloadURL) internal var _downloadURL: URL @NSManaged public private(set) var platformURLs: PlatformURLs? @@ -356,7 +356,7 @@ internal extension StoreApp // Preserve backwards compatibility by assigning legacy property values. guard let latestVersion = versions.first else { preconditionFailure("StoreApp must have at least one AppVersion.") } - self._version = latestVersion.version + self.latestVersionString = latestVersion.version self._versionDate = latestVersion.date self._versionDescription = latestVersion.localizedDescription self._downloadURL = latestVersion.downloadURL