Skip to content

Commit 65fd3d0

Browse files
committed
fix: address review issues in plugin marketplace
1 parent d3beeb5 commit 65fd3d0

File tree

4 files changed

+15
-32
lines changed

4 files changed

+15
-32
lines changed

TablePro/Core/Plugins/Registry/PluginManager+Registry.swift

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import CryptoKit
77
import Foundation
8-
import os
98

109
extension PluginManager {
1110
func installFromRegistry(
@@ -40,41 +39,32 @@ extension PluginManager {
4039
try? FileManager.default.removeItem(at: tempDir)
4140
}
4241

43-
let (asyncBytes, response) = try await URLSession.shared.bytes(from: downloadURL)
42+
// Use the registry client's configured session for consistent timeouts
43+
let session = await RegistryClient.shared.session
44+
45+
let (tempDownloadURL, response) = try await session.download(from: downloadURL)
4446

4547
guard let httpResponse = response as? HTTPURLResponse,
4648
(200...299).contains(httpResponse.statusCode) else {
4749
let statusCode = (response as? HTTPURLResponse)?.statusCode ?? 0
4850
throw PluginError.downloadFailed("HTTP \(statusCode)")
4951
}
5052

51-
let expectedLength = httpResponse.expectedContentLength
52-
var downloadedData = Data()
53-
if expectedLength > 0 {
54-
downloadedData.reserveCapacity(Int(expectedLength))
55-
}
56-
57-
var bytesReceived: Int64 = 0
58-
for try await byte in asyncBytes {
59-
downloadedData.append(byte)
60-
bytesReceived += 1
61-
62-
if expectedLength > 0, bytesReceived % 65_536 == 0 {
63-
let fraction = Double(bytesReceived) / Double(expectedLength)
64-
await progress(min(fraction, 1.0))
65-
}
66-
}
67-
68-
await progress(1.0)
53+
await progress(0.5)
6954

55+
// Verify SHA-256 checksum
56+
let downloadedData = try Data(contentsOf: tempDownloadURL)
7057
let digest = SHA256.hash(data: downloadedData)
7158
let hexChecksum = digest.map { String(format: "%02x", $0) }.joined()
7259

7360
if hexChecksum != registryPlugin.sha256.lowercased() {
7461
throw PluginError.checksumMismatch
7562
}
7663

77-
try downloadedData.write(to: tempZipURL)
64+
await progress(1.0)
65+
66+
// Move to our temp directory for installPlugin
67+
try FileManager.default.moveItem(at: tempDownloadURL, to: tempZipURL)
7868

7969
return try await installPlugin(from: tempZipURL)
8070
}

TablePro/Core/Plugins/Registry/RegistryClient.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class RegistryClient {
1919
set { UserDefaults.standard.set(newValue, forKey: "registryETag") }
2020
}
2121

22-
private let session: URLSession
22+
let session: URLSession
2323
private static let logger = Logger(subsystem: "com.TablePro", category: "RegistryClient")
2424

2525
// swiftlint:disable:next force_unwrapping
@@ -29,11 +29,6 @@ final class RegistryClient {
2929
private static let manifestCacheKey = "registryManifestCache"
3030
private static let lastFetchKey = "registryLastFetch"
3131

32-
private let decoder: JSONDecoder = {
33-
let decoder = JSONDecoder()
34-
return decoder
35-
}()
36-
3732
private init() {
3833
let config = URLSessionConfiguration.default
3934
config.timeoutIntervalForRequest = 15
@@ -42,7 +37,7 @@ final class RegistryClient {
4237
self.session = URLSession(configuration: config)
4338

4439
if let cachedData = UserDefaults.standard.data(forKey: Self.manifestCacheKey),
45-
let cached = try? decoder.decode(RegistryManifest.self, from: cachedData) {
40+
let cached = try? JSONDecoder().decode(RegistryManifest.self, from: cachedData) {
4641
manifest = cached
4742
lastFetchDate = UserDefaults.standard.object(forKey: Self.lastFetchKey) as? Date
4843
}
@@ -71,7 +66,7 @@ final class RegistryClient {
7166
fetchState = .loaded
7267

7368
case 200...299:
74-
let decoded = try decoder.decode(RegistryManifest.self, from: data)
69+
let decoded = try JSONDecoder().decode(RegistryManifest.self, from: data)
7570
manifest = decoded
7671

7772
UserDefaults.standard.set(data, forKey: Self.manifestCacheKey)
@@ -129,7 +124,7 @@ final class RegistryClient {
129124
}
130125
}
131126

132-
enum RegistryFetchState: Equatable {
127+
enum RegistryFetchState: Equatable, Sendable {
133128
case idle
134129
case loading
135130
case loaded

TablePro/Views/Settings/Plugins/BrowsePluginsView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ struct BrowsePluginsView: View {
117117
plugin: plugin,
118118
isInstalled: isPluginInstalled(plugin.id),
119119
installProgress: installTracker.state(for: plugin.id),
120-
isExpanded: selectedPluginId == plugin.id,
121120
onInstall: { installPlugin(plugin) },
122121
onToggleDetail: {
123122
withAnimation(.easeInOut(duration: 0.2)) {

TablePro/Views/Settings/Plugins/RegistryPluginRow.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ struct RegistryPluginRow: View {
99
let plugin: RegistryPlugin
1010
let isInstalled: Bool
1111
let installProgress: InstallProgress?
12-
let isExpanded: Bool
1312
let onInstall: () -> Void
1413
let onToggleDetail: () -> Void
1514

0 commit comments

Comments
 (0)