Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Xcodes/Backend/AppState+Install.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ extension AppState {
}

private func getXcodeArchiveAsync(_ installationType: InstallationType, downloader: Downloader) async throws -> (AvailableXcode, URL) {
let installedXcodes = await updateInstalledXcodesAsync(recomposeAllXcodes: false)

switch installationType {
case .version(let availableXcode):
let resolution = try mapInstallResolutionError {
try XcodeInstallResolutionService().resolve(
.availableXcode(availableXcode),
availableXcodes: [],
installedXcodes: Current.files.installedXcodes(Path.installDirectory),
installedXcodes: installedXcodes,
willInstall: true
)
}
Expand Down
2 changes: 2 additions & 0 deletions Xcodes/Backend/AppState+Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extension AppState {
updateTaskID = nil
}
}
await self.updateInstalledXcodesAsync()
await self.updateSelectedXcodePathAsync()
}
updateTask = task
Expand All @@ -49,6 +50,7 @@ extension AppState {
}
}
do {
await self.updateInstalledXcodesAsync()
await self.updateSelectedXcodePathAsync()
let xcodes = try await self.updateAvailableXcodes(from: self.dataSource)
try Task.checkCancellation()
Expand Down
26 changes: 24 additions & 2 deletions Xcodes/Backend/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AppState: ObservableObject {
}
updateAllXcodes(
availableXcodes: newValue,
installedXcodes: Current.files.installedXcodes(Path.installDirectory),
installedXcodes: installedXcodes,
selectedXcodePath: selectedXcodePath
)
}
Expand All @@ -61,11 +61,12 @@ class AppState: ObservableObject {
willSet {
updateAllXcodes(
availableXcodes: availableXcodes,
installedXcodes: Current.files.installedXcodes(Path.installDirectory),
installedXcodes: installedXcodes,
selectedXcodePath: newValue
)
}
}
private var installedXcodes: [InstalledXcode] = []
@Published var updateTask: Task<Void, Never>?
var updateTaskID: UUID?
var isUpdating: Bool { updateTask != nil }
Expand Down Expand Up @@ -228,6 +229,9 @@ class AppState: ObservableObject {
guard !isTesting else { return }
try? loadCachedAvailableXcodes()
try? loadCacheDownloadableRuntimes()
Task { @MainActor in
await updateInstalledXcodesAsync()
}
helperStatusTask = Task { @MainActor in
await checkIfHelperIsInstalled()
helperStatusTask = nil
Expand Down Expand Up @@ -855,6 +859,24 @@ class AppState: ObservableObject {
}
}

@discardableResult
func updateInstalledXcodesAsync(recomposeAllXcodes: Bool = true) async -> [InstalledXcode] {
let installDirectory = Path.installDirectory
let files = Current.files
let installedXcodes = await Task.detached(priority: .userInitiated) {
files.installedXcodes(installDirectory)
}.value

self.installedXcodes = installedXcodes
if recomposeAllXcodes {
updateAllXcodes(
availableXcodes: availableXcodes,
installedXcodes: installedXcodes,
selectedXcodePath: selectedXcodePath
)
}
return installedXcodes
}

// MARK: - Private

Expand Down
Loading