mirror of
https://github.com/XcodesOrg/XcodesApp.git
synced 2026-04-27 15:07:39 +00:00
Add dock progress indicator
in .bar style
This commit is contained in:
parent
ff73109f06
commit
ec41e4ab49
2 changed files with 13 additions and 1 deletions
|
|
@ -5,6 +5,7 @@ import AppleAPI
|
||||||
import Version
|
import Version
|
||||||
import LegibleError
|
import LegibleError
|
||||||
import os.log
|
import os.log
|
||||||
|
import DockProgress
|
||||||
|
|
||||||
/// Downloads and installs Xcodes
|
/// Downloads and installs Xcodes
|
||||||
extension AppState {
|
extension AppState {
|
||||||
|
|
@ -119,6 +120,7 @@ extension AppState {
|
||||||
cookies
|
cookies
|
||||||
)
|
)
|
||||||
progressChanged(progress)
|
progressChanged(progress)
|
||||||
|
updateDockIcon(withProgress: progress)
|
||||||
return publisher
|
return publisher
|
||||||
.map { _ in destination.url }
|
.map { _ in destination.url }
|
||||||
.eraseToAnyPublisher()
|
.eraseToAnyPublisher()
|
||||||
|
|
@ -128,11 +130,12 @@ extension AppState {
|
||||||
let resumeDataPath = Path.xcodesApplicationSupport/"Xcode-\(availableXcode.version).resumedata"
|
let resumeDataPath = Path.xcodesApplicationSupport/"Xcode-\(availableXcode.version).resumedata"
|
||||||
let persistedResumeData = Current.files.contents(atPath: resumeDataPath.string)
|
let persistedResumeData = Current.files.contents(atPath: resumeDataPath.string)
|
||||||
|
|
||||||
return attemptResumableTask(maximumRetryCount: 3) { resumeData -> AnyPublisher<URL, Error> in
|
return attemptResumableTask(maximumRetryCount: 3) { [weak self] resumeData -> AnyPublisher<URL, Error> in
|
||||||
let (progress, publisher) = Current.network.downloadTask(with: availableXcode.url,
|
let (progress, publisher) = Current.network.downloadTask(with: availableXcode.url,
|
||||||
to: destination.url,
|
to: destination.url,
|
||||||
resumingWith: resumeData ?? persistedResumeData)
|
resumingWith: resumeData ?? persistedResumeData)
|
||||||
progressChanged(progress)
|
progressChanged(progress)
|
||||||
|
self?.updateDockIcon(withProgress: progress)
|
||||||
return publisher
|
return publisher
|
||||||
.map { $0.saveLocation }
|
.map { $0.saveLocation }
|
||||||
.eraseToAnyPublisher()
|
.eraseToAnyPublisher()
|
||||||
|
|
@ -142,6 +145,11 @@ extension AppState {
|
||||||
})
|
})
|
||||||
.eraseToAnyPublisher()
|
.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func updateDockIcon(withProgress progress: Progress) {
|
||||||
|
DockProgress.style = .bar
|
||||||
|
DockProgress.progressInstance = progress
|
||||||
|
}
|
||||||
|
|
||||||
public func installArchivedXcode(_ availableXcode: AvailableXcode, at archiveURL: URL) -> AnyPublisher<InstalledXcode, Error> {
|
public func installArchivedXcode(_ availableXcode: AvailableXcode, at archiveURL: URL) -> AnyPublisher<InstalledXcode, Error> {
|
||||||
do {
|
do {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import LegibleError
|
||||||
import KeychainAccess
|
import KeychainAccess
|
||||||
import Path
|
import Path
|
||||||
import Version
|
import Version
|
||||||
|
import DockProgress
|
||||||
|
|
||||||
class AppState: ObservableObject {
|
class AppState: ObservableObject {
|
||||||
private let client = AppleAPI.Client()
|
private let client = AppleAPI.Client()
|
||||||
|
|
@ -298,6 +299,9 @@ class AppState: ObservableObject {
|
||||||
|
|
||||||
// Cancel the publisher
|
// Cancel the publisher
|
||||||
installationPublishers[id] = nil
|
installationPublishers[id] = nil
|
||||||
|
|
||||||
|
// Remove dock icon progress indicator
|
||||||
|
DockProgress.progress = 1 // Only way to completely remove overlay with DockProgress is setting progress to complete
|
||||||
|
|
||||||
// If the download is cancelled by the user, clean up the download files that aria2 creates.
|
// If the download is cancelled by the user, clean up the download files that aria2 creates.
|
||||||
// This isn't done as part of the publisher with handleEvents(receiveCancel:) because it shouldn't happen when e.g. the app quits.
|
// This isn't done as part of the publisher with handleEvents(receiveCancel:) because it shouldn't happen when e.g. the app quits.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue