mirror of
https://github.com/XcodesOrg/XcodesApp.git
synced 2026-03-25 08:55:46 +00:00
Merge pull request #423 from senmu/sam/dockProgress
Add installation progress bar to dock icon
This commit is contained in:
commit
5edeb60835
6 changed files with 90 additions and 1 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
|
@ -13,5 +13,5 @@ jobs:
|
|||
- uses: actions/checkout@v3
|
||||
- name: Run tests
|
||||
env:
|
||||
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app
|
||||
DEVELOPER_DIR: /Applications/Xcode_14.2.app
|
||||
run: xcodebuild test -scheme Xcodes
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@
|
|||
E8E98A9025D8631800EC89A0 /* InstallationStepRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAFBC3FF259AC17F00E2A3D8 /* InstallationStepRowView.swift */; };
|
||||
E8E98A9625D863D700EC89A0 /* InstallationStepDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8E98A9525D863D700EC89A0 /* InstallationStepDetailView.swift */; };
|
||||
E8F81FC4282D8A17006CBD0F /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = E8F81FC3282D8A17006CBD0F /* Sparkle */; };
|
||||
E689540325BE8C64000EBCEA /* DockProgress in Frameworks */ = {isa = PBXBuildFile; productRef = E689540225BE8C64000EBCEA /* DockProgress */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
|
|
@ -327,6 +328,7 @@
|
|||
E8F81FC4282D8A17006CBD0F /* Sparkle in Frameworks */,
|
||||
CABFA9E42592F08E00380FEE /* Version in Frameworks */,
|
||||
CABFA9FD2592F13300380FEE /* LegibleError in Frameworks */,
|
||||
E689540325BE8C64000EBCEA /* DockProgress in Frameworks */,
|
||||
CA9FF86D25951C6E00E47BAF /* XCModel in Frameworks */,
|
||||
CABFA9F82592F0F900380FEE /* KeychainAccess in Frameworks */,
|
||||
CAA858CD25A3D8BC00ACF8C0 /* ErrorHandling in Frameworks */,
|
||||
|
|
@ -666,6 +668,7 @@
|
|||
CA9FF86C25951C6E00E47BAF /* XCModel */,
|
||||
CAA858CC25A3D8BC00ACF8C0 /* ErrorHandling */,
|
||||
E8F81FC3282D8A17006CBD0F /* Sparkle */,
|
||||
E689540225BE8C64000EBCEA /* DockProgress */,
|
||||
);
|
||||
productName = XcodesMac;
|
||||
productReference = CAD2E79E2449574E00113D76 /* Xcodes.app */;
|
||||
|
|
@ -750,6 +753,7 @@
|
|||
CAA858CB25A3D8BC00ACF8C0 /* XCRemoteSwiftPackageReference "ErrorHandling" */,
|
||||
CAC28186259EE27200B8AB0B /* XCRemoteSwiftPackageReference "CombineExpectations" */,
|
||||
E8F81FC2282D8A17006CBD0F /* XCRemoteSwiftPackageReference "Sparkle" */,
|
||||
E689540125BE8C64000EBCEA /* XCRemoteSwiftPackageReference "DockProgress" */,
|
||||
);
|
||||
productRefGroup = CAD2E79F2449574E00113D76 /* Products */;
|
||||
projectDirPath = "";
|
||||
|
|
@ -1478,6 +1482,14 @@
|
|||
minimumVersion = 2.0.0;
|
||||
};
|
||||
};
|
||||
E689540125BE8C64000EBCEA /* XCRemoteSwiftPackageReference "DockProgress" */ = {
|
||||
isa = XCRemoteSwiftPackageReference;
|
||||
repositoryURL = "https://github.com/sindresorhus/DockProgress";
|
||||
requirement = {
|
||||
kind = upToNextMinorVersion;
|
||||
minimumVersion = 3.2.0;
|
||||
};
|
||||
};
|
||||
/* End XCRemoteSwiftPackageReference section */
|
||||
|
||||
/* Begin XCSwiftPackageProductDependency section */
|
||||
|
|
@ -1530,6 +1542,11 @@
|
|||
package = E8F81FC2282D8A17006CBD0F /* XCRemoteSwiftPackageReference "Sparkle" */;
|
||||
productName = Sparkle;
|
||||
};
|
||||
E689540225BE8C64000EBCEA /* DockProgress */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = E689540125BE8C64000EBCEA /* XCRemoteSwiftPackageReference "DockProgress" */;
|
||||
productName = DockProgress;
|
||||
};
|
||||
/* End XCSwiftPackageProductDependency section */
|
||||
};
|
||||
rootObject = CAD2E7962449574E00113D76 /* Project object */;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,15 @@
|
|||
"version": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "DockProgress",
|
||||
"repositoryURL": "https://github.com/sindresorhus/DockProgress",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "7100b68571e2dafe3a06ad5905b80fc3b0107b4b",
|
||||
"version": "3.2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "ErrorHandling",
|
||||
"repositoryURL": "https://github.com/RobotsAndPencils/ErrorHandling",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import AppleAPI
|
|||
import Version
|
||||
import LegibleError
|
||||
import os.log
|
||||
import DockProgress
|
||||
|
||||
/// Downloads and installs Xcodes
|
||||
extension AppState {
|
||||
|
|
@ -43,6 +44,8 @@ extension AppState {
|
|||
|
||||
Logger.appState.info("Using \(downloader) downloader")
|
||||
|
||||
setupDockProgress()
|
||||
|
||||
return validateSession()
|
||||
.flatMap { _ in
|
||||
self.getXcodeArchive(installationType, downloader: downloader)
|
||||
|
|
@ -51,6 +54,8 @@ extension AppState {
|
|||
self.installArchivedXcode(xcode, at: url)
|
||||
}
|
||||
.catch { error -> AnyPublisher<InstalledXcode, Swift.Error> in
|
||||
self.resetDockProgressTracking()
|
||||
|
||||
switch error {
|
||||
case InstallationError.damagedXIP(let damagedXIPURL):
|
||||
guard attemptNumber < 1 else { return Fail(error: error).eraseToAnyPublisher() }
|
||||
|
|
@ -99,6 +104,7 @@ extension AppState {
|
|||
self.downloadOrUseExistingArchive(for: availableXcode, downloader: downloader, progressChanged: { [unowned self] progress in
|
||||
DispatchQueue.main.async {
|
||||
self.setInstallationStep(of: availableXcode.version, to: .downloading(progress: progress))
|
||||
self.overallProgress.addChild(progress, withPendingUnitCount: AppState.totalProgressUnits - AppState.unxipProgressWeight)
|
||||
}
|
||||
})
|
||||
.map { return (availableXcode, $0) }
|
||||
|
|
@ -151,6 +157,7 @@ extension AppState {
|
|||
cookies
|
||||
)
|
||||
progressChanged(progress)
|
||||
|
||||
return publisher
|
||||
.map { _ in destination.url }
|
||||
.eraseToAnyPublisher()
|
||||
|
|
@ -165,6 +172,7 @@ extension AppState {
|
|||
to: destination.url,
|
||||
resumingWith: resumeData ?? persistedResumeData)
|
||||
progressChanged(progress)
|
||||
|
||||
return publisher
|
||||
.map { $0.saveLocation }
|
||||
.eraseToAnyPublisher()
|
||||
|
|
@ -176,6 +184,9 @@ extension AppState {
|
|||
}
|
||||
|
||||
public func installArchivedXcode(_ availableXcode: AvailableXcode, at archiveURL: URL) -> AnyPublisher<InstalledXcode, Error> {
|
||||
unxipProgress.completedUnitCount = 0
|
||||
overallProgress.addChild(unxipProgress, withPendingUnitCount: AppState.unxipProgressWeight)
|
||||
|
||||
do {
|
||||
let destinationURL = Path.installDirectory.join("Xcode-\(availableXcode.version.descriptionWithoutBuildMetadata).app").url
|
||||
switch archiveURL.pathExtension {
|
||||
|
|
@ -415,6 +426,9 @@ extension AppState {
|
|||
}
|
||||
self.presentedAlert = .privilegedHelper
|
||||
}
|
||||
|
||||
unxipProgress.completedUnitCount = AppState.totalProgressUnits
|
||||
resetDockProgressTracking()
|
||||
|
||||
return helperInstallConsentSubject
|
||||
.flatMap {
|
||||
|
|
@ -455,6 +469,24 @@ extension AppState {
|
|||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
// MARK: - Dock Progress Tracking
|
||||
|
||||
private func setupDockProgress() {
|
||||
DockProgress.progressInstance = nil
|
||||
DockProgress.style = .bar
|
||||
|
||||
let progress = Progress(totalUnitCount: AppState.totalProgressUnits)
|
||||
progress.kind = .file
|
||||
progress.fileOperationKind = .downloading
|
||||
overallProgress = progress
|
||||
|
||||
DockProgress.progressInstance = overallProgress
|
||||
}
|
||||
|
||||
func resetDockProgressTracking() {
|
||||
DockProgress.progress = 1 // Only way to completely remove overlay with DockProgress is setting progress to complete
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
|
||||
func setInstallationStep(of version: Version, to step: InstallationStep) {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import KeychainAccess
|
|||
import Path
|
||||
import Version
|
||||
import os.log
|
||||
import DockProgress
|
||||
|
||||
class AppState: ObservableObject {
|
||||
private let client = AppleAPI.Client()
|
||||
|
|
@ -106,6 +107,19 @@ class AppState: ObservableObject {
|
|||
private var selectPublisher: AnyCancellable?
|
||||
private var uninstallPublisher: AnyCancellable?
|
||||
private var autoInstallTimer: Timer?
|
||||
|
||||
// MARK: - Dock Progress Tracking
|
||||
|
||||
public static let totalProgressUnits = Int64(10)
|
||||
public static let unxipProgressWeight = Int64(1)
|
||||
var overallProgress = Progress()
|
||||
var unxipProgress = {
|
||||
let progress = Progress(totalUnitCount: totalProgressUnits)
|
||||
progress.kind = .file
|
||||
progress.fileOperationKind = .copying
|
||||
return progress
|
||||
}()
|
||||
|
||||
// MARK: -
|
||||
|
||||
var dataSource: DataSource {
|
||||
|
|
@ -489,6 +503,8 @@ class AppState: ObservableObject {
|
|||
|
||||
// Cancel the publisher
|
||||
installationPublishers[id] = nil
|
||||
|
||||
resetDockProgressTracking()
|
||||
|
||||
// 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.
|
||||
|
|
|
|||
|
|
@ -308,6 +308,21 @@ For more information, please refer to <<http://unlicense.org/>>\
|
|||
otherwise be required by Sections 4(a), 4(b) and 4(d) of the License.\
|
||||
\
|
||||
|
||||
\fs34 DockProgress\
|
||||
\
|
||||
|
||||
\fs26 MIT License\
|
||||
\
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)\
|
||||
\
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\
|
||||
\
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\
|
||||
\
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\
|
||||
\
|
||||
\
|
||||
|
||||
\fs34 KeychainAccess\
|
||||
\
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue