Skip to content

Commit 6ffce23

Browse files
committed
more WIP
1 parent 487cbb0 commit 6ffce23

21 files changed

Lines changed: 234 additions & 228 deletions

Xcodes.xcodeproj/project.pbxproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
CABFAA492593162500380FEE /* Bundle+InfoPlistValues.swift in Sources */ = {isa = PBXBuildFile; fileRef = CABFAA482593162500380FEE /* Bundle+InfoPlistValues.swift */; };
8080
CAC28188259EE27200B8AB0B /* CombineExpectations in Frameworks */ = {isa = PBXBuildFile; productRef = CAC28187259EE27200B8AB0B /* CombineExpectations */; };
8181
CAC281CD259F97FA00B8AB0B /* ObservingProgressIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAC281CC259F97FA00B8AB0B /* ObservingProgressIndicator.swift */; };
82-
CAC281DA259F985100B8AB0B /* InstallationStep.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAC281D9259F985100B8AB0B /* InstallationStep.swift */; };
8382
CAC281E2259FA44600B8AB0B /* Bundle+XcodesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAC281E1259FA44600B8AB0B /* Bundle+XcodesTests.swift */; };
8483
CAC281E7259FA45A00B8AB0B /* Environment+Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAC281E6259FA45A00B8AB0B /* Environment+Mock.swift */; };
8584
CAC9F92D25BCDA4400B4965F /* HelperInstallState.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAC9F92C25BCDA4400B4965F /* HelperInstallState.swift */; };
@@ -269,7 +268,6 @@
269268
CABFAA422593104F00380FEE /* AboutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutView.swift; sourceTree = "<group>"; };
270269
CABFAA482593162500380FEE /* Bundle+InfoPlistValues.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bundle+InfoPlistValues.swift"; sourceTree = "<group>"; };
271270
CAC281CC259F97FA00B8AB0B /* ObservingProgressIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObservingProgressIndicator.swift; sourceTree = "<group>"; };
272-
CAC281D9259F985100B8AB0B /* InstallationStep.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstallationStep.swift; sourceTree = "<group>"; };
273271
CAC281E1259FA44600B8AB0B /* Bundle+XcodesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bundle+XcodesTests.swift"; sourceTree = "<group>"; };
274272
CAC281E6259FA45A00B8AB0B /* Environment+Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Environment+Mock.swift"; sourceTree = "<group>"; };
275273
CAC9F92C25BCDA4400B4965F /* HelperInstallState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HelperInstallState.swift; sourceTree = "<group>"; };
@@ -482,7 +480,6 @@
482480
CABFA9AC2592EEE900380FEE /* Foundation.swift */,
483481
CA9FF9352595B44700E47BAF /* HelperClient.swift */,
484482
CAC9F92C25BCDA4400B4965F /* HelperInstallState.swift */,
485-
CAC281D9259F985100B8AB0B /* InstallationStep.swift */,
486483
CA9FF8862595607900E47BAF /* InstalledXcode.swift */,
487484
CAA8587B25A2B37900ACF8C0 /* IsTesting.swift */,
488485
E89342F925EDCC17007CF557 /* NotificationManager.swift */,
@@ -863,7 +860,6 @@
863860
CAFE4ABC25B7D54B0064FE51 /* UpdatesPreferencePane.swift in Sources */,
864861
CABFA9BD2592EEEA00380FEE /* Environment.swift in Sources */,
865862
CABFA9C32592EEEA00380FEE /* Downloads.swift in Sources */,
866-
CAC281DA259F985100B8AB0B /* InstallationStep.swift in Sources */,
867863
E8CBDB8B27AE02FF00B22292 /* ExperiementsPreferencePane.swift in Sources */,
868864
E8E98A9625D863D700EC89A0 /* InstallationStepDetailView.swift in Sources */,
869865
CA378F992466567600A58CE0 /* AppState.swift in Sources */,
@@ -1427,8 +1423,6 @@
14271423
isa = XCRemoteSwiftPackageReference;
14281424
repositoryURL = "https://github.com/xcodereleases/data";
14291425
requirement = {
1430-
kind = revision;
1431-
revision = a43ad89e536d7a3da525fcc23fb182c37b756ecc;
14321426
branch = main;
14331427
kind = branch;
14341428
};

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

Lines changed: 3 additions & 3 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: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ extension AppState {
490490

491491
// MARK: -
492492

493-
func setInstallationStep(of version: Version, to step: InstallationStep) {
493+
func setInstallationStep(of version: Version, to step: XcodeInstallationStep) {
494494
DispatchQueue.main.async {
495495
guard let index = self.allXcodes.firstIndex(where: { $0.version.isEquivalent(to: version) }) else { return }
496496
self.allXcodes[index].installState = .installing(step)
@@ -499,14 +499,13 @@ extension AppState {
499499
Current.notificationManager.scheduleNotification(title: xcode.id.appleDescription, body: step.description, category: .normal)
500500
}
501501
}
502-
func setInstallationStep(of runtime: DownloadableRuntime, to step: InstallationStep) {
502+
func setInstallationStep(of runtime: DownloadableRuntime, to step: RuntimeInstallationStep) {
503503
DispatchQueue.main.async {
504504

505505
guard let index = self.downloadableRuntimes.firstIndex(where: { $0.identifier == runtime.identifier }) else { return }
506506
self.downloadableRuntimes[index].installState = .installing(step)
507507

508-
// let xcode = self.allXcodes[index]
509-
// Current.notificationManager.scheduleNotification(title: xcode.id.appleDescription, body: step.description, category: .normal)
508+
Current.notificationManager.scheduleNotification(title: runtime.name, body: step.description, category: .normal)
510509
}
511510
}
512511
}

Xcodes/Backend/AppState+Runtimes.swift

Lines changed: 63 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ extension AppState {
4747

4848
func downloadRuntime(runtime: DownloadableRuntime) {
4949
Task {
50-
try? await downloadRunTimeFull(runtime: runtime)
50+
do {
51+
try await downloadRunTimeFull(runtime: runtime)
52+
}
53+
catch {
54+
Logger.appState.error("Error downloading runtime: \(error.localizedDescription)")
55+
}
5156
}
5257

5358
// self.runtimePublishers[runtime.identifier] = downloadRunTimeFull(runtime: runtime)
@@ -78,33 +83,20 @@ extension AppState {
7883
let downloader = Downloader(rawValue: UserDefaults.standard.string(forKey: "downloader") ?? "aria2") ?? .aria2
7984
Logger.appState.info("Downloading \(runtime.visibleIdentifier) with \(downloader)")
8085

81-
82-
return validateADCSession(path: runtime.downloadPath)
83-
.flatMap { _ in
84-
// we shouldn't have to be authenticated to download runtimes
85-
let downloader = Downloader(rawValue: UserDefaults.standard.string(forKey: "downloader") ?? "aria2") ?? .aria2
86-
Logger.appState.info("Downloading \(runtime.visibleIdentifier) with \(downloader)")
87-
88-
return self.downloadRuntime(for: runtime, downloader: downloader, progressChanged: { [unowned self] progress in
89-
DispatchQueue.main.async {
90-
self.setInstallationStep(of: runtime, to: .downloading(progress: progress))
91-
}
92-
})
93-
.map { return (runtime, $0) }
86+
let url = try await self.downloadRuntime(for: runtime, downloader: downloader, progressChanged: { [unowned self] progress in
87+
DispatchQueue.main.async {
88+
self.setInstallationStep(of: runtime, to: .downloading(progress: progress))
9489
}
95-
.flatMap { runtime, url -> AnyPublisher<URL, Error> in
96-
switch runtime.contentType {
97-
case .package:
98-
return self.installFromPackage(dmgURL: url, runtime: runtime)
99-
case .diskImage:
100-
return self.installFromImage(dmgURL: url)
101-
}
102-
}
103-
.map { url in
104-
// Done deleting
105-
Logger.appState.debug("URL: \(url)")
106-
}
107-
.eraseToAnyPublisher()
90+
}).async()
91+
92+
Logger.appState.debug("Done downloading: \(url)")
93+
//self.setInstallationStep(of: runtime, to: .downloading(progress: progress))
94+
switch runtime.contentType {
95+
case .package:
96+
try await self.installFromPackage(dmgURL: url, runtime: runtime)
97+
case .diskImage:
98+
try await self.installFromImage(dmgURL: url)
99+
}
108100
}
109101

110102
func downloadRuntime(for runtime: DownloadableRuntime, downloader: Downloader, progressChanged: @escaping (Progress) -> Void) -> AnyPublisher<URL, Error> {
@@ -142,7 +134,7 @@ extension AppState {
142134
progressChanged: progressChanged)
143135

144136
case .urlSession:
145-
137+
// TODO: Support runtime download via URL Session
146138
return Just(runtime.url)
147139
.setFailureType(to: Error.self)
148140
.eraseToAnyPublisher()
@@ -171,53 +163,56 @@ extension AppState {
171163
.eraseToAnyPublisher()
172164
}
173165

174-
public func downloadRuntimeWithAria2(_ runtime: DownloadableRuntime, to destination: Path, aria2Path: Path, progressChanged: @escaping (Progress) -> Void) async -> URL {
175-
176-
}
177166

178-
public func installFromImage(dmgURL: URL) -> AnyPublisher<URL, Error> {
167+
public func installFromImage(dmgURL: URL) async throws {
179168

180-
181-
try? self.runtimeService.installRuntimeImage(dmgURL: dmgURL)
182-
183-
184-
return Just(dmgURL)
185-
.setFailureType(to: Error.self)
186-
.eraseToAnyPublisher()
169+
try? self.runtimeService.installRuntimeImage(dmgURL: dmgURL)
187170

188171
}
189172

190-
public func installFromPackage(dmgURL: URL, runtime: DownloadableRuntime) -> AnyPublisher<URL, Error> {
173+
public func installFromPackage(dmgURL: URL, runtime: DownloadableRuntime) async throws {
191174
Logger.appState.info("Mounting DMG")
192-
Task {
193-
do {
194-
let mountedUrl = try await self.runtimeService.mountDMG(dmgUrl: dmgURL)
195-
196-
// 2-Get the first path under the mounted path, should be a .pkg
197-
let pkgPath = Path(url: mountedUrl)!.ls().first!
198-
try Path.xcodesCaches.mkdir().setCurrentUserAsOwner()
199-
200-
let expandedPkgPath = Path.xcodesCaches/runtime.identifier
201-
//try expandedPkgPath.mkdir()
202-
Logger.appState.info("PKG Path: \(pkgPath)")
203-
Logger.appState.info("Expanded PKG Path: \(expandedPkgPath)")
204-
//try? Current.files.removeItem(at: expandedPkgPath.url)
205-
206-
// 5-Expand (not install) the pkg to temporary path
207-
try await self.runtimeService.expand(pkgPath: pkgPath, expandedPkgPath: expandedPkgPath)
208-
//try await self.runtimeService.unmountDMG(mountedURL: mountedUrl)
209-
210-
} catch {
211-
Logger.appState.error("Error installing runtime: \(error.localizedDescription)")
212-
}
175+
176+
do {
177+
let mountedUrl = try await self.runtimeService.mountDMG(dmgUrl: dmgURL)
213178

179+
// 2-Get the first path under the mounted path, should be a .pkg
180+
let pkgPath = Path(url: mountedUrl)!.ls().first!
181+
try Path.xcodesCaches.mkdir().setCurrentUserAsOwner()
182+
183+
let expandedPkgPath = Path.xcodesCaches/runtime.identifier
184+
//try expandedPkgPath.mkdir()
185+
Logger.appState.info("PKG Path: \(pkgPath)")
186+
Logger.appState.info("Expanded PKG Path: \(expandedPkgPath)")
187+
//try? Current.files.removeItem(at: expandedPkgPath.url)
188+
189+
// 5-Expand (not install) the pkg to temporary path
190+
try await self.runtimeService.expand(pkgPath: pkgPath, expandedPkgPath: expandedPkgPath)
191+
//try await self.runtimeService.unmountDMG(mountedURL: mountedUrl)
192+
193+
} catch {
194+
Logger.appState.error("Error installing runtime: \(error.localizedDescription)")
195+
}
196+
}
197+
}
198+
199+
extension AnyPublisher {
200+
func async() async throws -> Output {
201+
try await withCheckedThrowingContinuation { continuation in
202+
var cancellable: AnyCancellable?
203+
204+
cancellable = first()
205+
.sink { result in
206+
switch result {
207+
case .finished:
208+
break
209+
case let .failure(error):
210+
continuation.resume(throwing: error)
211+
}
212+
cancellable?.cancel()
213+
} receiveValue: { value in
214+
continuation.resume(with: .success(value))
215+
}
214216
}
215-
216-
217-
218-
return Just(dmgURL)
219-
.setFailureType(to: Error.self)
220-
.eraseToAnyPublisher()
221217
}
222-
223218
}

0 commit comments

Comments
 (0)