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