@@ -19,14 +19,18 @@ private let installPath = homeDirectory
19
19
final class RegistryManager {
20
20
static let shared : RegistryManager = . init( )
21
21
22
- private let saveLocation = installPath
22
+ /// The URL of where the registry.json file will be downloaded from
23
23
private let registryURL = URL (
24
24
string: " https://github.com/mason-org/mason-registry/releases/latest/download/registry.json.zip "
25
25
) !
26
+ /// The URL of where the checksums.txt file will be downloaded from
26
27
private let checksumURL = URL (
27
28
string: " https://github.com/mason-org/mason-registry/releases/latest/download/checksums.txt "
28
29
) !
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
30
34
31
35
/// Rreference to cached registry data. Will be removed from memory after a certain amount of time.
32
36
private var cachedRegistry : CachedRegistry ?
@@ -59,6 +63,11 @@ final class RegistryManager {
59
63
@AppSettings ( \. languageServers. installedLanguageServers)
60
64
var installedLanguageServers : [ String : SettingsData . InstalledLanguageServer ]
61
65
66
+ private init ( ) {
67
+ installQueue = OperationQueue ( )
68
+ installQueue. maxConcurrentOperationCount = maxConcurrentInstallations
69
+ }
70
+
62
71
deinit {
63
72
cleanupTimer? . invalidate ( )
64
73
}
@@ -70,26 +79,26 @@ final class RegistryManager {
70
79
71
80
do {
72
81
// 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 )
74
83
75
84
let ( registryData, checksumData) = try await ( zipDataTask, checksumsTask)
76
85
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 " )
79
88
80
89
do {
81
90
// Delete existing zip data if it exists
82
91
if FileManager . default. fileExists ( atPath: tempZipURL. path) {
83
92
try FileManager . default. removeItem ( at: tempZipURL)
84
93
}
85
- let registryJsonPath = saveLocation . appending ( path: " registry.json " ) . path
94
+ let registryJsonPath = installPath . appending ( path: " registry.json " ) . path
86
95
if FileManager . default. fileExists ( atPath: registryJsonPath) {
87
96
try FileManager . default. removeItem ( atPath: registryJsonPath)
88
97
}
89
98
90
99
// Write the zip data to a temporary file, then unzip
91
100
try registryData. write ( to: tempZipURL)
92
- try FileManager . default. unzipItem ( at: tempZipURL, to: saveLocation )
101
+ try FileManager . default. unzipItem ( at: tempZipURL, to: installPath )
93
102
try FileManager . default. removeItem ( at: tempZipURL)
94
103
95
104
try checksumData. write ( to: checksumDestination)
@@ -180,7 +189,7 @@ final class RegistryManager {
180
189
181
190
/// Loads registry items from disk
182
191
private func loadItemsFromDisk( ) -> [ RegistryItem ] ? {
183
- let registryPath = saveLocation . appending ( path: " registry.json " )
192
+ let registryPath = installPath . appending ( path: " registry.json " )
184
193
let fileManager = FileManager . default
185
194
186
195
// Update the file every 24 hours
0 commit comments