From 389af4d5e6f77b111f8da6c4176b4b3b6024e34c Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Wed, 29 Nov 2023 18:08:42 -0600 Subject: [PATCH] Switches from StoreApp.isBeta to isPledged to determine whether app is visible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If StoreApp.isHiddenWithoutPledge == false (default), we’ll still show the app. --- AltStore/Browse/BrowseViewController.swift | 4 ++-- AltStore/My Apps/MyAppsViewController.swift | 5 ++--- .../Sources/SourceDetailContentViewController.swift | 2 +- AltStore/Sources/SourcesViewController.swift | 10 +--------- AltStoreCore/Model/InstalledApp.swift | 8 +++++++- AltStoreCore/Model/StoreApp.swift | 12 ++++++++++++ 6 files changed, 25 insertions(+), 16 deletions(-) diff --git a/AltStore/Browse/BrowseViewController.swift b/AltStore/Browse/BrowseViewController.swift index c4dde587..26d08355 100644 --- a/AltStore/Browse/BrowseViewController.swift +++ b/AltStore/Browse/BrowseViewController.swift @@ -93,7 +93,6 @@ class BrowseViewController: UICollectionViewController, PeekPopPreviewing super.viewWillAppear(animated) self.fetchSource() - self.updateDataSource() self.update() } @@ -110,7 +109,8 @@ private extension BrowseViewController NSSortDescriptor(keyPath: \StoreApp.bundleIdentifier, ascending: true)] fetchRequest.returnsObjectsAsFaults = false - let predicate = NSPredicate(format: "%K != %@", #keyPath(StoreApp.bundleIdentifier), StoreApp.altstoreAppID) + let predicate = StoreApp.visibleAppsPredicate + if let source = self.source { let filterPredicate = NSPredicate(format: "%K == %@", #keyPath(StoreApp._source), source) diff --git a/AltStore/My Apps/MyAppsViewController.swift b/AltStore/My Apps/MyAppsViewController.swift index f3724691..3993c73a 100644 --- a/AltStore/My Apps/MyAppsViewController.swift +++ b/AltStore/My Apps/MyAppsViewController.swift @@ -113,11 +113,10 @@ class MyAppsViewController: UICollectionViewController, PeekPopPreviewing (self as PeekPopPreviewing).registerForPreviewing(with: self, sourceView: self.collectionView) } - override func viewWillAppear(_ animated: Bool) + override func viewIsAppearing(_ animated: Bool) { - super.viewWillAppear(animated) + super.viewIsAppearing(animated) - self.updateDataSource() self.update() self.fetchAppIDs() diff --git a/AltStore/Sources/SourceDetailContentViewController.swift b/AltStore/Sources/SourceDetailContentViewController.swift index 525b435d..e2cd8eb0 100644 --- a/AltStore/Sources/SourceDetailContentViewController.swift +++ b/AltStore/Sources/SourceDetailContentViewController.swift @@ -215,7 +215,7 @@ private extension SourceDetailContentViewController let dataSource = RSTArrayCollectionViewPrefetchingDataSource(items: limitedFeaturedApps) dataSource.cellIdentifierHandler = { _ in "AppCell" } - dataSource.predicate = NSPredicate(format: "%K == NO", #keyPath(StoreApp.isBeta)) // Never show beta apps (at least until we support betas for other sources). + dataSource.predicate = StoreApp.visibleAppsPredicate dataSource.cellConfigurationHandler = { [weak self] (cell, storeApp, indexPath) in let cell = cell as! AppBannerCollectionViewCell cell.tintColor = storeApp.tintColor diff --git a/AltStore/Sources/SourcesViewController.swift b/AltStore/Sources/SourcesViewController.swift index 47594fc5..4ac57061 100644 --- a/AltStore/Sources/SourcesViewController.swift +++ b/AltStore/Sources/SourcesViewController.swift @@ -231,15 +231,7 @@ private extension SourcesViewController cell.bannerView.iconImageView.image = nil cell.bannerView.iconImageView.isIndicatingActivity = true - let numberOfApps: Int - if let patreonAccount = DatabaseManager.shared.patreonAccount(), patreonAccount.isPatron, PatreonAPI.shared.isAuthenticated - { - numberOfApps = source.apps.count - } - else - { - numberOfApps = source.apps.filter { !$0.isBeta }.count - } + let numberOfApps = source.apps.filter { StoreApp.visibleAppsPredicate.evaluate(with: $0) }.count if let error = source.error { diff --git a/AltStoreCore/Model/InstalledApp.swift b/AltStoreCore/Model/InstalledApp.swift index 871b4c14..4207c960 100644 --- a/AltStoreCore/Model/InstalledApp.swift +++ b/AltStoreCore/Model/InstalledApp.swift @@ -212,13 +212,19 @@ public extension InstalledApp // We have to also check !(latestSupportedVersion.buildVersion == '' && installedApp.storeBuildVersion == nil) // because latestSupportedVersion.buildVersion stores an empty string for nil, while installedApp.storeBuildVersion uses NULL. "(%K != %K OR (%K != %K AND NOT (%K == '' AND %K == nil)))", + + "AND", + + // !isPledgeRequired || isPledged + "(%K == NO OR %K == YES)" ].joined(separator: " ") fetchRequest.predicate = NSPredicate(format: predicateFormat, #keyPath(InstalledApp.isActive), #keyPath(InstalledApp.storeApp), #keyPath(InstalledApp.storeApp.latestSupportedVersion), #keyPath(InstalledApp.storeApp.latestSupportedVersion.version), #keyPath(InstalledApp.version), #keyPath(InstalledApp.storeApp.latestSupportedVersion._buildVersion), #keyPath(InstalledApp.storeBuildVersion), - #keyPath(InstalledApp.storeApp.latestSupportedVersion._buildVersion), #keyPath(InstalledApp.storeBuildVersion)) + #keyPath(InstalledApp.storeApp.latestSupportedVersion._buildVersion), #keyPath(InstalledApp.storeBuildVersion), + #keyPath(InstalledApp.storeApp.isPledgeRequired), #keyPath(InstalledApp.storeApp.isPledged)) return fetchRequest } diff --git a/AltStoreCore/Model/StoreApp.swift b/AltStoreCore/Model/StoreApp.swift index 09275f4a..194ab8cf 100644 --- a/AltStoreCore/Model/StoreApp.swift +++ b/AltStoreCore/Model/StoreApp.swift @@ -569,6 +569,18 @@ public extension StoreApp let globallyUniqueID = self.bundleIdentifier + "|" + sourceIdentifier return globallyUniqueID } +} + +public extension StoreApp +{ + class var visibleAppsPredicate: NSPredicate { + let predicate = NSPredicate(format: "(%K != %@) AND ((%K == NO) OR (%K == NO) OR (%K == YES))", + #keyPath(StoreApp.bundleIdentifier), StoreApp.altstoreAppID, + #keyPath(StoreApp.isPledgeRequired), + #keyPath(StoreApp.isHiddenWithoutPledge), + #keyPath(StoreApp.isPledged)) + return predicate + } @nonobjc class func fetchRequest() -> NSFetchRequest {