Skip to content

Commit de35bed

Browse files
Sam Lusenmu
authored andcommitted
Add dock progress indicator
in .bar style
1 parent 9dd91a2 commit de35bed

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

Xcodes/Backend/AppState+Install.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import AppleAPI
55
import Version
66
import LegibleError
77
import os.log
8+
import DockProgress
89

910
/// Downloads and installs Xcodes
1011
extension AppState {
@@ -151,6 +152,7 @@ extension AppState {
151152
cookies
152153
)
153154
progressChanged(progress)
155+
updateDockIcon(withProgress: progress)
154156
return publisher
155157
.map { _ in destination.url }
156158
.eraseToAnyPublisher()
@@ -160,11 +162,12 @@ extension AppState {
160162
let resumeDataPath = Path.xcodesApplicationSupport/"Xcode-\(availableXcode.version).resumedata"
161163
let persistedResumeData = Current.files.contents(atPath: resumeDataPath.string)
162164

163-
return attemptResumableTask(maximumRetryCount: 3) { resumeData -> AnyPublisher<URL, Error> in
165+
return attemptResumableTask(maximumRetryCount: 3) { [weak self] resumeData -> AnyPublisher<URL, Error> in
164166
let (progress, publisher) = Current.network.downloadTask(with: availableXcode.url,
165167
to: destination.url,
166168
resumingWith: resumeData ?? persistedResumeData)
167169
progressChanged(progress)
170+
self?.updateDockIcon(withProgress: progress)
168171
return publisher
169172
.map { $0.saveLocation }
170173
.eraseToAnyPublisher()
@@ -174,6 +177,11 @@ extension AppState {
174177
})
175178
.eraseToAnyPublisher()
176179
}
180+
181+
private func updateDockIcon(withProgress progress: Progress) {
182+
DockProgress.style = .bar
183+
DockProgress.progressInstance = progress
184+
}
177185

178186
public func installArchivedXcode(_ availableXcode: AvailableXcode, at archiveURL: URL) -> AnyPublisher<InstalledXcode, Error> {
179187
do {

Xcodes/Backend/AppState.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import KeychainAccess
77
import Path
88
import Version
99
import os.log
10+
import DockProgress
1011

1112
class AppState: ObservableObject {
1213
private let client = AppleAPI.Client()
@@ -489,6 +490,9 @@ class AppState: ObservableObject {
489490

490491
// Cancel the publisher
491492
installationPublishers[id] = nil
493+
494+
// Remove dock icon progress indicator
495+
DockProgress.progress = 1 // Only way to completely remove overlay with DockProgress is setting progress to complete
492496

493497
// If the download is cancelled by the user, clean up the download files that aria2 creates.
494498
// This isn't done as part of the publisher with handleEvents(receiveCancel:) because it shouldn't happen when e.g. the app quits.

0 commit comments

Comments
 (0)