@@ -49,9 +49,18 @@ extension AppState {
4949 Task {
5050 do {
5151 try await downloadRunTimeFull ( runtime: runtime)
52+
53+ DispatchQueue . main. async {
54+ guard let index = self . downloadableRuntimes. firstIndex ( where: { $0. identifier == runtime. identifier } ) else { return }
55+ self . downloadableRuntimes [ index] . installState = . installed
56+ }
5257 }
5358 catch {
5459 Logger . appState. error ( " Error downloading runtime: \( error. localizedDescription) " )
60+ DispatchQueue . main. async {
61+ self . error = error
62+ self . presentedAlert = . generic( title: localizeString ( " Alert.Install.Error.Title " ) , message: error. legibleLocalizedDescription)
63+ }
5564 }
5665 }
5766
@@ -83,22 +92,31 @@ extension AppState {
8392 let downloader = Downloader ( rawValue: UserDefaults . standard. string ( forKey: " downloader " ) ?? " aria2 " ) ?? . aria2
8493 Logger . appState. info ( " Downloading \( runtime. visibleIdentifier) with \( downloader) " )
8594
95+
8696 let url = try await self . downloadRuntime ( for: runtime, downloader: downloader, progressChanged: { [ unowned self] progress in
8797 DispatchQueue . main. async {
8898 self . setInstallationStep ( of: runtime, to: . downloading( progress: progress) )
8999 }
90100 } ) . async ( )
91101
92102 Logger . appState. debug ( " Done downloading: \( url) " )
93- //self.setInstallationStep(of: runtime, to: .downloading(progress: progress))
103+ DispatchQueue . main. async {
104+ self . setInstallationStep ( of: runtime, to: . installing)
105+ }
94106 switch runtime. contentType {
95107 case . package :
96- try await self . installFromPackage ( dmgURL: url, runtime: runtime)
108+ // not supported yet (do we need to for old packages?)
109+ throw " Installing via package not support - please install manually from \( url. description) "
97110 case . diskImage:
98111 try await self . installFromImage ( dmgURL: url)
112+ DispatchQueue . main. async {
113+ self . setInstallationStep ( of: runtime, to: . trashingArchive)
114+ }
115+ try Current . files. removeItem ( at: url)
99116 }
100117 }
101118
119+ @MainActor
102120 func downloadRuntime( for runtime: DownloadableRuntime , downloader: Downloader , progressChanged: @escaping ( Progress ) -> Void ) -> AnyPublisher < URL , Error > {
103121 // Check to see if the dmg is in the expected path in case it was downloaded but failed to install
104122
@@ -139,9 +157,9 @@ extension AppState {
139157 . setFailureType ( to: Error . self)
140158 . eraseToAnyPublisher ( )
141159
142- // return downloadXcodeWithURLSession (
143- // availableXcode ,
144- // to: destination ,
160+ // return downloadRuntimeWithURLSession (
161+ // runtime ,
162+ // to: expectedRuntimePath ,
145163// progressChanged: progressChanged
146164// )
147165 }
@@ -163,36 +181,8 @@ extension AppState {
163181 . eraseToAnyPublisher ( )
164182 }
165183
166-
167184 public func installFromImage( dmgURL: URL ) async throws {
168-
169- try ? self . runtimeService. installRuntimeImage ( dmgURL: dmgURL)
170-
171- }
172-
173- public func installFromPackage( dmgURL: URL , runtime: DownloadableRuntime ) async throws {
174- Logger . appState. info ( " Mounting DMG " )
175-
176- do {
177- let mountedUrl = try await self . runtimeService. mountDMG ( dmgUrl: dmgURL)
178-
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- }
185+ try await self . runtimeService. installRuntimeImage ( dmgURL: dmgURL)
196186 }
197187}
198188
0 commit comments