@@ -9,11 +9,24 @@ import Foundation
99import CorkShared
1010import CorkModels
1111import CorkTerminalFunctions
12+ import Defaults
1213
1314@Observable
1415class InstallationProgressTracker
1516{
16- var packageBeingInstalled : PackageInProgressOfBeingInstalled = . init( package : . init( name: " " , type: . formula, installedOn: nil , versions: [ ] , url: nil , sizeInBytes: 0 , downloadCount: nil ) , installationStage: . downloadingCask, packageInstallationProgress: 0 )
17+ var packageBeingInstalled : PackageInProgressOfBeingInstalled = . init(
18+ package : . init(
19+ rawName: " " ,
20+ type: . formula,
21+ installedOn: nil ,
22+ versions: [ ] ,
23+ url: nil ,
24+ sizeInBytes: 0 ,
25+ downloadCount: nil
26+ ) ,
27+ installationStage: . downloadingCask,
28+ packageInstallationProgress: 0
29+ )
1730
1831 var numberOfPackageDependencies : Int = 0
1932 var numberInLineOfPackageCurrentlyBeingFetched : Int = 0
@@ -23,7 +36,7 @@ class InstallationProgressTracker
2336
2437 private var showRealTimeTerminalOutputs : Bool
2538 {
26- UserDefaults . standard . bool ( forKey : " showRealTimeTerminalOutputOfOperations " )
39+ Defaults [ . showRealTimeTerminalOutputOfOperations]
2740 }
2841
2942 deinit
@@ -45,13 +58,13 @@ class InstallationProgressTracker
4558 {
4659 let package : BrewPackage = packageBeingInstalled. package
4760
48- AppConstants . shared. logger. debug ( " Installing package \( package . name, privacy: . auto) " )
61+ AppConstants . shared. logger. debug ( " Installing package \( package . name ( withPrecision : . precise ) , privacy: . auto) " )
4962
5063 var installationResult : TerminalOutput = . init( standardOutput: " " , standardError: " " )
5164
5265 if package . type == . formula
5366 {
54- AppConstants . shared. logger. info ( " Package \( package . name, privacy: . public) is Formula " )
67+ AppConstants . shared. logger. info ( " Package \( package . name ( withPrecision : . precise ) , privacy: . public) is Formula " )
5568
5669 let output : String = try await installFormula ( using: brewPackagesTracker) . joined ( separator: " " )
5770
@@ -88,9 +101,9 @@ class InstallationProgressTracker
88101 var hasAlreadyMatchedLineAboutInstallingPackageItself : Bool = false
89102 var installOutput : [ String ] = . init( )
90103
91- AppConstants . shared. logger. info ( " Package \( package . name, privacy: . public) is Formula " )
104+ AppConstants . shared. logger. info ( " Package \( package . name ( withPrecision : . precise ) , privacy: . public) is Formula " )
92105
93- let ( stream, process) : ( AsyncStream < StreamedTerminalOutput > , Process ) = shell ( AppConstants . shared. brewExecutablePath, [ " install " , package . name] )
106+ let ( stream, process) : ( AsyncStream < StreamedTerminalOutput > , Process ) = shell ( AppConstants . shared. brewExecutablePath, [ " install " , package . name ( withPrecision : . precise ) ] )
94107 installationProcess = process
95108 for await output in stream
96109 {
@@ -110,7 +123,7 @@ class InstallationProgressTracker
110123 if outputLine. contains ( " Fetching dependencies " )
111124 {
112125 // First, we have to get a list of all the dependencies
113- var matchedDependencies : String = try outputLine. regexMatch ( " (?<= \( package . name) : ).*?(.*) " )
126+ var matchedDependencies : String = try outputLine. regexMatch ( " (?<= \( package . name ( withPrecision : . precise ) ) : ).*?(.*) " )
114127 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
115128
116129 AppConstants . shared. logger. debug ( " Matched Dependencies: \( matchedDependencies, privacy: . auto) " )
@@ -126,7 +139,7 @@ class InstallationProgressTracker
126139 packageBeingInstalled. packageInstallationProgress = 1
127140 }
128141
129- else if outputLine. contains ( " Installing dependencies " ) || outputLine. contains ( " Installing \( package . name) dependency " )
142+ else if outputLine. contains ( " Installing dependencies " ) || outputLine. contains ( " Installing \( package . name ( withPrecision : . precise ) ) dependency " )
130143 {
131144 AppConstants . shared. logger. info ( " Will install dependencies! " )
132145 packageBeingInstalled. installationStage = . installingDependencies
@@ -151,7 +164,7 @@ class InstallationProgressTracker
151164 packageBeingInstalled. packageInstallationProgress = packageBeingInstalled. packageInstallationProgress + Double( Double ( 10 ) / ( Double ( 3 ) * ( Double ( numberOfPackageDependencies) * Double( 5 ) ) ) )
152165 }
153166
154- else if outputLine. contains ( " Fetching \( package . name) " ) || outputLine. contains ( " Installing \( package . name) " )
167+ else if outputLine. contains ( " Fetching \( package . name ( withPrecision : . precise ) ) " ) || outputLine. contains ( " Installing \( package . name ( withPrecision : . precise ) ) " )
155168 {
156169 if hasAlreadyMatchedLineAboutInstallingPackageItself
157170 { /// Only the second line about the package being installed is valid
@@ -205,9 +218,9 @@ class InstallationProgressTracker
205218 let package : BrewPackage = packageBeingInstalled. package
206219
207220 AppConstants . shared. logger. info ( " Package is Cask " )
208- AppConstants . shared. logger. debug ( " Installing package \( package . name, privacy: . public) " )
221+ AppConstants . shared. logger. debug ( " Installing package \( package . name ( withPrecision : . precise ) , privacy: . public) " )
209222
210- let ( stream, process) : ( AsyncStream < StreamedTerminalOutput > , Process ) = shell ( AppConstants . shared. brewExecutablePath, [ " install " , package . name] )
223+ let ( stream, process) : ( AsyncStream < StreamedTerminalOutput > , Process ) = shell ( AppConstants . shared. brewExecutablePath, [ " install " , package . name ( withPrecision : . precise ) ] )
211224 installationProcess = process
212225 for await output in stream
213226 {
@@ -255,7 +268,7 @@ class InstallationProgressTracker
255268 }
256269 else if outputLine. contains ( " Purging files " )
257270 {
258- AppConstants . shared. logger. info ( " Purging old version of cask \( package . name) " )
271+ AppConstants . shared. logger. info ( " Purging old version of cask \( package . name ( withPrecision : . precise ) ) " )
259272
260273 packageBeingInstalled. installationStage = . installingCask
261274
0 commit comments