55// Created by David Bureš on 22.02.2023.
66//
77
8- import Foundation
98import CorkShared
9+ import Foundation
1010
1111class InstallationProgressTracker : ObservableObject
1212{
1313 @Published var installationStage : PackageInstallationStage = . downloadingCask
1414 @Published var installationProgress : Double = 0
15-
15+
1616 @Published var realTimeTerminalOutput : [ RealTimeTerminalLine ] = . init( )
17-
17+
1818 @Published var numberOfPackageDependencies : Int = 0
1919 @Published var numberInLineOfPackageCurrentlyBeingFetched : Int = 0
2020 @Published var numberInLineOfPackageCurrentlyBeingInstalled : Int = 0
21-
21+
2222 private var installationProcess : Process ?
2323
2424 private var showRealTimeTerminalOutputs : Bool
2525 {
2626 UserDefaults . standard. bool ( forKey: " showRealTimeTerminalOutputOfOperations " )
2727 }
28-
28+
2929 deinit
3030 {
3131 cancel ( )
3232 }
33-
33+
3434 @discardableResult
3535 func cancel( ) -> Bool
3636 {
37- guard let installationProcess else { return false }
37+ guard let installationProcess else { return false }
3838 installationProcess. terminate ( )
3939 self . installationProcess = nil
4040 return true
@@ -87,7 +87,7 @@ class InstallationProgressTracker: ObservableObject
8787
8888 AppConstants . shared. logger. info ( " Package \( packageToInstall. name, privacy: . public) is Formula " )
8989
90- let ( stream, process) : ( AsyncStream < StreamedTerminalOutput > , Process ) = shell ( AppConstants . shared. brewExecutablePath, [ " install " , packageToInstall. name ] )
90+ let ( stream, process) : ( AsyncStream < StreamedTerminalOutput > , Process ) = shell ( AppConstants . shared. brewExecutablePath, [ " install " , packageToInstall. fullName ] )
9191 installationProcess = process
9292 for await output in stream
9393 {
@@ -107,7 +107,7 @@ class InstallationProgressTracker: ObservableObject
107107 if outputLine. contains ( " Fetching dependencies " )
108108 {
109109 // First, we have to get a list of all the dependencies
110- var matchedDependencies : String = try outputLine. regexMatch ( " (?<= \( packageToInstall. name ) : ).*?(.*) " )
110+ var matchedDependencies : String = try outputLine. regexMatch ( " (?<= \( packageToInstall. fullName ) : ).*?(.*) " )
111111 matchedDependencies = matchedDependencies. replacingOccurrences ( of: " and " , with: " , " ) // The last dependency is different, because it's preceded by "and" instead of "," so let's replace that "and" with "," so we can split it nicely
112112
113113 AppConstants . shared. logger. debug ( " Matched Dependencies: \( matchedDependencies, privacy: . auto) " )
@@ -170,7 +170,7 @@ class InstallationProgressTracker: ObservableObject
170170
171171 installOutput. append ( outputLine)
172172
173- AppConstants . shared. logger. debug ( " Current installation stage: \( self . installationStage. description, privacy: . public) " )
173+ AppConstants . shared. logger. debug ( " Current installation stage: \( self . installationStage. description, privacy: . public) " )
174174
175175 case . standardError( let errorLine) :
176176 AppConstants . shared. logger. error ( " Errored out: \( errorLine, privacy: . public) " )
@@ -202,7 +202,7 @@ class InstallationProgressTracker: ObservableObject
202202 AppConstants . shared. logger. info ( " Package is Cask " )
203203 AppConstants . shared. logger. debug ( " Installing package \( packageToInstall. name, privacy: . public) " )
204204
205- let ( stream, process) : ( AsyncStream < StreamedTerminalOutput > , Process ) = shell ( AppConstants . shared. brewExecutablePath, [ " install " , " --no-quarantine " , packageToInstall. name ] )
205+ let ( stream, process) : ( AsyncStream < StreamedTerminalOutput > , Process ) = shell ( AppConstants . shared. brewExecutablePath, [ " install " , " --no-quarantine " , packageToInstall. fullName ] )
206206 installationProcess = process
207207 for await output in stream
208208 {
@@ -213,7 +213,7 @@ class InstallationProgressTracker: ObservableObject
213213
214214 if showRealTimeTerminalOutputs
215215 {
216- realTimeTerminalOutput. append ( RealTimeTerminalLine ( line: outputLine) )
216+ realTimeTerminalOutput. append ( RealTimeTerminalLine ( line: outputLine) )
217217 }
218218
219219 if outputLine. contains ( " Downloading " )
0 commit comments