[AltStoreCore] Adds Source.isAdded

Convenience property to determine whether a source has been added to the user’s AltStore.
This commit is contained in:
Riley Testut
2023-04-04 14:19:05 -05:00
committed by Magesh K
parent 12ca34f40f
commit 20cd6d98fc

View File

@@ -356,6 +356,28 @@ public class Source: NSManagedObject, Fetchable, Decodable
}
}
public extension Source
{
// Source is considered added IFF it has been saved to disk,
// which we can check by fetching on a new managed object context.
var isAdded: Bool {
get async throws {
let identifier = await AsyncManaged(wrappedValue: self).identifier
let backgroundContext = DatabaseManager.shared.persistentContainer.newBackgroundContext()
let isAdded = try await backgroundContext.performAsync {
let fetchRequest = Source.fetchRequest()
fetchRequest.predicate = NSPredicate(format: "%K == %@", #keyPath(Source.identifier), identifier)
let count = try backgroundContext.count(for: fetchRequest)
return (count > 0)
}
return isAdded
}
}
}
internal extension Source
{
func setFeaturedApps(_ featuredApps: [StoreApp]?)