mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
[AltStoreCore] Adds Source.isAdded
Convenience property to determine whether a source has been added to the user’s AltStore.
This commit is contained in:
@@ -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]?)
|
||||
|
||||
Reference in New Issue
Block a user