From 1cfd83bbb783ccfc694bce791fac3fdc902dd084 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Wed, 16 Nov 2022 14:11:11 -0600 Subject: [PATCH] =?UTF-8?q?Hides=20app=20updates=20that=20don=E2=80=99t=20?= =?UTF-8?q?support=20device=E2=80=99s=20OS=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AltStore/Managing Apps/AppManager.swift | 4 ++-- AltStore/My Apps/MyAppsViewController.swift | 18 ++++++++++-------- AltStoreCore/Model/InstalledApp.swift | 16 +++++++++++++++- .../StoreApp10ToStoreApp11Policy.swift | 2 +- AltStoreCore/Model/StoreApp.swift | 8 ++++---- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/AltStore/Managing Apps/AppManager.swift b/AltStore/Managing Apps/AppManager.swift index 39c43b2c..ce36742c 100644 --- a/AltStore/Managing Apps/AppManager.swift +++ b/AltStore/Managing Apps/AppManager.swift @@ -395,9 +395,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 cf48b470..28f2b0e4 100644 --- a/AltStore/My Apps/MyAppsViewController.swift +++ b/AltStore/My Apps/MyAppsViewController.swift @@ -185,7 +185,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 @@ -479,6 +479,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) @@ -489,13 +498,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 41ff1475..b23926df 100644 --- a/AltStoreCore/Model/InstalledApp.swift +++ b/AltStoreCore/Model/InstalledApp.swift @@ -146,7 +146,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 9b2163bf..3a679935 100644 --- a/AltStoreCore/Model/StoreApp.swift +++ b/AltStoreCore/Model/StoreApp.swift @@ -40,9 +40,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 tintColor: UIColor? @@ -226,7 +226,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