From 5df4169a1b5aa3207b382b0329629f39831c6442 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Thu, 10 Sep 2020 11:27:44 -0700 Subject: [PATCH] Refines AppManager Combine pipeline --- AltStore/Managing Apps/AppManager.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/AltStore/Managing Apps/AppManager.swift b/AltStore/Managing Apps/AppManager.swift index d9a284ad..e5950e12 100644 --- a/AltStore/Managing Apps/AppManager.swift +++ b/AltStore/Managing Apps/AppManager.swift @@ -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) }