mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
[AltStore] Tracks refresh progress in addition to installation
This commit is contained in:
@@ -26,7 +26,8 @@ class AppManager
|
||||
private let operationQueue = OperationQueue()
|
||||
private let processingQueue = DispatchQueue(label: "com.altstore.AppManager.processingQueue")
|
||||
|
||||
private var installationProgress = [App: Progress]()
|
||||
private var installationProgress = [String: Progress]()
|
||||
private var refreshProgress = [String: Progress]()
|
||||
|
||||
private init()
|
||||
{
|
||||
@@ -112,11 +113,13 @@ extension AppManager
|
||||
return progress
|
||||
}
|
||||
|
||||
let appIdentifier = app.identifier
|
||||
|
||||
let group = self.install([app], forceDownload: true, presentingViewController: presentingViewController)
|
||||
group.completionHandler = { (result) in
|
||||
do
|
||||
{
|
||||
self.installationProgress[app] = nil
|
||||
self.installationProgress[appIdentifier] = nil
|
||||
|
||||
guard let (_, result) = try result.get().first else { throw OperationError.unknown }
|
||||
completionHandler(result)
|
||||
@@ -127,22 +130,35 @@ extension AppManager
|
||||
}
|
||||
}
|
||||
|
||||
self.installationProgress[app] = group.progress
|
||||
self.installationProgress[app.identifier] = group.progress
|
||||
|
||||
return group.progress
|
||||
}
|
||||
|
||||
func refresh(_ installedApps: [InstalledApp], presentingViewController: UIViewController?, group: OperationGroup? = nil) -> OperationGroup
|
||||
{
|
||||
let apps = installedApps.compactMap { $0.app }
|
||||
let apps = installedApps.compactMap { $0.app }.filter { self.refreshProgress(for: $0) == nil }
|
||||
|
||||
let group = self.install(apps, forceDownload: false, presentingViewController: presentingViewController, group: group)
|
||||
|
||||
for app in apps
|
||||
{
|
||||
guard let progress = group.progress(for: app) else { continue }
|
||||
self.refreshProgress[app.identifier] = progress
|
||||
}
|
||||
|
||||
return group
|
||||
}
|
||||
|
||||
func installationProgress(for app: App) -> Progress?
|
||||
{
|
||||
let progress = self.installationProgress[app]
|
||||
let progress = self.installationProgress[app.identifier]
|
||||
return progress
|
||||
}
|
||||
|
||||
func refreshProgress(for app: App) -> Progress?
|
||||
{
|
||||
let progress = self.refreshProgress[app.identifier]
|
||||
return progress
|
||||
}
|
||||
}
|
||||
@@ -250,9 +266,8 @@ private extension AppManager
|
||||
progress.addChild(installOperation.progress, withPendingUnitCount: 30)
|
||||
installOperation.addDependency(sendAppOperation)
|
||||
operations.append(installOperation)
|
||||
|
||||
group.progress.totalUnitCount += 1
|
||||
group.progress.addChild(progress, withPendingUnitCount: 1)
|
||||
|
||||
group.set(progress, for: app)
|
||||
}
|
||||
|
||||
group.addOperations(operations)
|
||||
@@ -302,6 +317,8 @@ private extension AppManager
|
||||
}
|
||||
}
|
||||
|
||||
self.refreshProgress[context.appIdentifier] = nil
|
||||
|
||||
print("Finished operation!", context.appIdentifier)
|
||||
|
||||
if context.group.results.count == context.group.progress.totalUnitCount
|
||||
|
||||
@@ -25,6 +25,8 @@ class OperationGroup
|
||||
|
||||
var results = [String: Result<InstalledApp, Error>]()
|
||||
|
||||
private var progressByApp = [App: Progress]()
|
||||
|
||||
private let operationQueue = OperationQueue()
|
||||
private let installOperationQueue = OperationQueue()
|
||||
|
||||
@@ -60,4 +62,18 @@ class OperationGroup
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func set(_ progress: Progress, for app: App)
|
||||
{
|
||||
self.progressByApp[app] = progress
|
||||
|
||||
self.progress.totalUnitCount += 1
|
||||
self.progress.addChild(progress, withPendingUnitCount: 1)
|
||||
}
|
||||
|
||||
func progress(for app: App) -> Progress?
|
||||
{
|
||||
let progress = self.progressByApp[app]
|
||||
return progress
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user