Refines AppManager Combine pipeline

This commit is contained in:
Riley Testut
2020-09-10 11:27:44 -07:00
parent 80a39889ca
commit 5df4169a1b

View File

@@ -76,16 +76,19 @@ class AppManager
@available(iOS 13, *)
func prepareSubscriptions()
{
/// Every time refreshProgress is changed, update all InstalledApps in memory
/// so that app.isRefreshing == refreshProgress.keys.contains(app.bundleID)
self.publisher.$refreshProgress
.receive(on: RunLoop.main)
.map(\.keys)
.flatMap { (bundleIDs) in
DatabaseManager.shared.viewContext.registeredObjects.publisher
.compactMap { $0 as? InstalledApp }
.map { ($0, bundleIDs) }
.map { ($0, bundleIDs.contains($0.bundleIdentifier)) }
}
.sink { (installedApp, bundleIDs) in
installedApp.isRefreshing = bundleIDs.contains(installedApp.bundleIdentifier)
.sink { (installedApp, isRefreshing) in
installedApp.isRefreshing = isRefreshing
}
.store(in: &self.cancellables)
}