@@ -19,14 +19,18 @@ private let installPath = homeDirectory
1919final class RegistryManager {
2020 static let shared : RegistryManager = . init( )
2121
22- private let saveLocation = installPath
22+ /// The URL of where the registry.json file will be downloaded from
2323 private let registryURL = URL (
2424 string: " https://github.com/mason-org/mason-registry/releases/latest/download/registry.json.zip "
2525 ) !
26+ /// The URL of where the checksums.txt file will be downloaded from
2627 private let checksumURL = URL (
2728 string: " https://github.com/mason-org/mason-registry/releases/latest/download/checksums.txt "
2829 ) !
29- private var cancellables : Set < AnyCancellable > = [ ]
30+ /// A queue for installing packages concurrently
31+ private let installQueue : OperationQueue
32+ /// The max amount of package concurrent installs
33+ private let maxConcurrentInstallations : Int = 2
3034
3135 /// Rreference to cached registry data. Will be removed from memory after a certain amount of time.
3236 private var cachedRegistry : CachedRegistry ?
@@ -59,6 +63,11 @@ final class RegistryManager {
5963 @AppSettings ( \. languageServers. installedLanguageServers)
6064 var installedLanguageServers : [ String : SettingsData . InstalledLanguageServer ]
6165
66+ private init ( ) {
67+ installQueue = OperationQueue ( )
68+ installQueue. maxConcurrentOperationCount = maxConcurrentInstallations
69+ }
70+
6271 deinit {
6372 cleanupTimer? . invalidate ( )
6473 }
@@ -70,26 +79,26 @@ final class RegistryManager {
7079
7180 do {
7281 // Make sure the extensions folder exists first
73- try FileManager . default. createDirectory ( at: saveLocation , withIntermediateDirectories: true )
82+ try FileManager . default. createDirectory ( at: installPath , withIntermediateDirectories: true )
7483
7584 let ( registryData, checksumData) = try await ( zipDataTask, checksumsTask)
7685
77- let tempZipURL = saveLocation . appending ( path: " temp.zip " )
78- let checksumDestination = saveLocation . appending ( path: " checksums.txt " )
86+ let tempZipURL = installPath . appending ( path: " temp.zip " )
87+ let checksumDestination = installPath . appending ( path: " checksums.txt " )
7988
8089 do {
8190 // Delete existing zip data if it exists
8291 if FileManager . default. fileExists ( atPath: tempZipURL. path) {
8392 try FileManager . default. removeItem ( at: tempZipURL)
8493 }
85- let registryJsonPath = saveLocation . appending ( path: " registry.json " ) . path
94+ let registryJsonPath = installPath . appending ( path: " registry.json " ) . path
8695 if FileManager . default. fileExists ( atPath: registryJsonPath) {
8796 try FileManager . default. removeItem ( atPath: registryJsonPath)
8897 }
8998
9099 // Write the zip data to a temporary file, then unzip
91100 try registryData. write ( to: tempZipURL)
92- try FileManager . default. unzipItem ( at: tempZipURL, to: saveLocation )
101+ try FileManager . default. unzipItem ( at: tempZipURL, to: installPath )
93102 try FileManager . default. removeItem ( at: tempZipURL)
94103
95104 try checksumData. write ( to: checksumDestination)
@@ -180,7 +189,7 @@ final class RegistryManager {
180189
181190 /// Loads registry items from disk
182191 private func loadItemsFromDisk( ) -> [ RegistryItem ] ? {
183- let registryPath = saveLocation . appending ( path: " registry.json " )
192+ let registryPath = installPath . appending ( path: " registry.json " )
184193 let fileManager = FileManager . default
185194
186195 // Update the file every 24 hours
0 commit comments