Skip to content

Commit 5edeb60

Browse files
authored
Merge pull request #423 from senmu/sam/dockProgress
Add installation progress bar to dock icon
2 parents 47710b6 + b6e654c commit 5edeb60

6 files changed

Lines changed: 90 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ jobs:
1313
- uses: actions/checkout@v3
1414
- name: Run tests
1515
env:
16-
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app
16+
DEVELOPER_DIR: /Applications/Xcode_14.2.app
1717
run: xcodebuild test -scheme Xcodes

Xcodes.xcodeproj/project.pbxproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
E8E98A9025D8631800EC89A0 /* InstallationStepRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAFBC3FF259AC17F00E2A3D8 /* InstallationStepRowView.swift */; };
117117
E8E98A9625D863D700EC89A0 /* InstallationStepDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8E98A9525D863D700EC89A0 /* InstallationStepDetailView.swift */; };
118118
E8F81FC4282D8A17006CBD0F /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = E8F81FC3282D8A17006CBD0F /* Sparkle */; };
119+
E689540325BE8C64000EBCEA /* DockProgress in Frameworks */ = {isa = PBXBuildFile; productRef = E689540225BE8C64000EBCEA /* DockProgress */; };
119120
/* End PBXBuildFile section */
120121

121122
/* Begin PBXContainerItemProxy section */
@@ -327,6 +328,7 @@
327328
E8F81FC4282D8A17006CBD0F /* Sparkle in Frameworks */,
328329
CABFA9E42592F08E00380FEE /* Version in Frameworks */,
329330
CABFA9FD2592F13300380FEE /* LegibleError in Frameworks */,
331+
E689540325BE8C64000EBCEA /* DockProgress in Frameworks */,
330332
CA9FF86D25951C6E00E47BAF /* XCModel in Frameworks */,
331333
CABFA9F82592F0F900380FEE /* KeychainAccess in Frameworks */,
332334
CAA858CD25A3D8BC00ACF8C0 /* ErrorHandling in Frameworks */,
@@ -666,6 +668,7 @@
666668
CA9FF86C25951C6E00E47BAF /* XCModel */,
667669
CAA858CC25A3D8BC00ACF8C0 /* ErrorHandling */,
668670
E8F81FC3282D8A17006CBD0F /* Sparkle */,
671+
E689540225BE8C64000EBCEA /* DockProgress */,
669672
);
670673
productName = XcodesMac;
671674
productReference = CAD2E79E2449574E00113D76 /* Xcodes.app */;
@@ -750,6 +753,7 @@
750753
CAA858CB25A3D8BC00ACF8C0 /* XCRemoteSwiftPackageReference "ErrorHandling" */,
751754
CAC28186259EE27200B8AB0B /* XCRemoteSwiftPackageReference "CombineExpectations" */,
752755
E8F81FC2282D8A17006CBD0F /* XCRemoteSwiftPackageReference "Sparkle" */,
756+
E689540125BE8C64000EBCEA /* XCRemoteSwiftPackageReference "DockProgress" */,
753757
);
754758
productRefGroup = CAD2E79F2449574E00113D76 /* Products */;
755759
projectDirPath = "";
@@ -1478,6 +1482,14 @@
14781482
minimumVersion = 2.0.0;
14791483
};
14801484
};
1485+
E689540125BE8C64000EBCEA /* XCRemoteSwiftPackageReference "DockProgress" */ = {
1486+
isa = XCRemoteSwiftPackageReference;
1487+
repositoryURL = "https://github.com/sindresorhus/DockProgress";
1488+
requirement = {
1489+
kind = upToNextMinorVersion;
1490+
minimumVersion = 3.2.0;
1491+
};
1492+
};
14811493
/* End XCRemoteSwiftPackageReference section */
14821494

14831495
/* Begin XCSwiftPackageProductDependency section */
@@ -1530,6 +1542,11 @@
15301542
package = E8F81FC2282D8A17006CBD0F /* XCRemoteSwiftPackageReference "Sparkle" */;
15311543
productName = Sparkle;
15321544
};
1545+
E689540225BE8C64000EBCEA /* DockProgress */ = {
1546+
isa = XCSwiftPackageProductDependency;
1547+
package = E689540125BE8C64000EBCEA /* XCRemoteSwiftPackageReference "DockProgress" */;
1548+
productName = DockProgress;
1549+
};
15331550
/* End XCSwiftPackageProductDependency section */
15341551
};
15351552
rootObject = CAD2E7962449574E00113D76 /* Project object */;

Xcodes.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Xcodes/Backend/AppState+Install.swift

Lines changed: 32 additions & 0 deletions
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 {
@@ -43,6 +44,8 @@ extension AppState {
4344

4445
Logger.appState.info("Using \(downloader) downloader")
4546

47+
setupDockProgress()
48+
4649
return validateSession()
4750
.flatMap { _ in
4851
self.getXcodeArchive(installationType, downloader: downloader)
@@ -51,6 +54,8 @@ extension AppState {
5154
self.installArchivedXcode(xcode, at: url)
5255
}
5356
.catch { error -> AnyPublisher<InstalledXcode, Swift.Error> in
57+
self.resetDockProgressTracking()
58+
5459
switch error {
5560
case InstallationError.damagedXIP(let damagedXIPURL):
5661
guard attemptNumber < 1 else { return Fail(error: error).eraseToAnyPublisher() }
@@ -99,6 +104,7 @@ extension AppState {
99104
self.downloadOrUseExistingArchive(for: availableXcode, downloader: downloader, progressChanged: { [unowned self] progress in
100105
DispatchQueue.main.async {
101106
self.setInstallationStep(of: availableXcode.version, to: .downloading(progress: progress))
107+
self.overallProgress.addChild(progress, withPendingUnitCount: AppState.totalProgressUnits - AppState.unxipProgressWeight)
102108
}
103109
})
104110
.map { return (availableXcode, $0) }
@@ -151,6 +157,7 @@ extension AppState {
151157
cookies
152158
)
153159
progressChanged(progress)
160+
154161
return publisher
155162
.map { _ in destination.url }
156163
.eraseToAnyPublisher()
@@ -165,6 +172,7 @@ extension AppState {
165172
to: destination.url,
166173
resumingWith: resumeData ?? persistedResumeData)
167174
progressChanged(progress)
175+
168176
return publisher
169177
.map { $0.saveLocation }
170178
.eraseToAnyPublisher()
@@ -176,6 +184,9 @@ extension AppState {
176184
}
177185

178186
public func installArchivedXcode(_ availableXcode: AvailableXcode, at archiveURL: URL) -> AnyPublisher<InstalledXcode, Error> {
187+
unxipProgress.completedUnitCount = 0
188+
overallProgress.addChild(unxipProgress, withPendingUnitCount: AppState.unxipProgressWeight)
189+
179190
do {
180191
let destinationURL = Path.installDirectory.join("Xcode-\(availableXcode.version.descriptionWithoutBuildMetadata).app").url
181192
switch archiveURL.pathExtension {
@@ -415,6 +426,9 @@ extension AppState {
415426
}
416427
self.presentedAlert = .privilegedHelper
417428
}
429+
430+
unxipProgress.completedUnitCount = AppState.totalProgressUnits
431+
resetDockProgressTracking()
418432

419433
return helperInstallConsentSubject
420434
.flatMap {
@@ -455,6 +469,24 @@ extension AppState {
455469
.eraseToAnyPublisher()
456470
}
457471

472+
// MARK: - Dock Progress Tracking
473+
474+
private func setupDockProgress() {
475+
DockProgress.progressInstance = nil
476+
DockProgress.style = .bar
477+
478+
let progress = Progress(totalUnitCount: AppState.totalProgressUnits)
479+
progress.kind = .file
480+
progress.fileOperationKind = .downloading
481+
overallProgress = progress
482+
483+
DockProgress.progressInstance = overallProgress
484+
}
485+
486+
func resetDockProgressTracking() {
487+
DockProgress.progress = 1 // Only way to completely remove overlay with DockProgress is setting progress to complete
488+
}
489+
458490
// MARK: -
459491

460492
func setInstallationStep(of version: Version, to step: InstallationStep) {

Xcodes/Backend/AppState.swift

Lines changed: 16 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()
@@ -106,6 +107,19 @@ class AppState: ObservableObject {
106107
private var selectPublisher: AnyCancellable?
107108
private var uninstallPublisher: AnyCancellable?
108109
private var autoInstallTimer: Timer?
110+
111+
// MARK: - Dock Progress Tracking
112+
113+
public static let totalProgressUnits = Int64(10)
114+
public static let unxipProgressWeight = Int64(1)
115+
var overallProgress = Progress()
116+
var unxipProgress = {
117+
let progress = Progress(totalUnitCount: totalProgressUnits)
118+
progress.kind = .file
119+
progress.fileOperationKind = .copying
120+
return progress
121+
}()
122+
109123
// MARK: -
110124

111125
var dataSource: DataSource {
@@ -489,6 +503,8 @@ class AppState: ObservableObject {
489503

490504
// Cancel the publisher
491505
installationPublishers[id] = nil
506+
507+
resetDockProgressTracking()
492508

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

Xcodes/Resources/Licenses.rtf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,21 @@ For more information, please refer to &lt;<http://unlicense.org/>&gt;\
308308
otherwise be required by Sections 4(a), 4(b) and 4(d) of the License.\
309309
\
310310

311+
\fs34 DockProgress\
312+
\
313+
314+
\fs26 MIT License\
315+
\
316+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)\
317+
\
318+
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:\
319+
\
320+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\
321+
\
322+
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.\
323+
\
324+
\
325+
311326
\fs34 KeychainAccess\
312327
\
313328

0 commit comments

Comments
 (0)