Skip to content

Commit c148b67

Browse files
committed
review
1 parent 5b4d965 commit c148b67

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

Diff for: Coder-Desktop/Coder-Desktop/Views/FileSync/FilePicker.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ class FilePickerModel: ObservableObject {
7878
@Published var isLoading: Bool = false
7979
@Published var error: ClientError?
8080

81-
let client: Client
81+
let client: AgentClient
8282

8383
init(host: String) {
84-
client = Client(url: URL(string: "http://\(host):4")!)
84+
client = AgentClient(agentHost: host)
8585
}
8686

8787
func loadRoot() {
@@ -176,7 +176,7 @@ class FilePickerItemModel: Identifiable, ObservableObject {
176176
// This being a binding is pretty important performance-wise, as it's a struct
177177
// that would otherwise be recreated every time the the item row is rendered.
178178
// Removing the binding results in very noticeable lag when scrolling a file tree.
179-
@Binding var client: Client
179+
@Binding var client: AgentClient
180180

181181
@Published var contents: [FilePickerItemModel]?
182182
@Published var isLoading = false
@@ -197,7 +197,7 @@ class FilePickerItemModel: Identifiable, ObservableObject {
197197

198198
init(
199199
name: String,
200-
client: Binding<Client>,
200+
client: Binding<AgentClient>,
201201
absolute_path: String,
202202
path: [String],
203203
dir: Bool = false,
@@ -237,7 +237,7 @@ class FilePickerItemModel: Identifiable, ObservableObject {
237237

238238
extension LSResponse {
239239
@MainActor
240-
func toModels(client: Binding<Client>, path: [String]) -> [FilePickerItemModel] {
240+
func toModels(client: Binding<AgentClient>, path: [String]) -> [FilePickerItemModel] {
241241
contents.compactMap { file in
242242
// Filter dotfiles from the picker
243243
guard !file.name.hasPrefix(".") else { return nil }

Diff for: Coder-Desktop/CoderSDK/AgentClient.swift

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public struct AgentClient: Sendable {
2+
let client: Client
3+
4+
public init(agentHost: String) {
5+
client = Client(url: URL(string: "http://\(agentHost):4")!)
6+
}
7+
}

Diff for: Coder-Desktop/CoderSDK/AgentLS.swift

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
public extension Client {
2-
// The Client's URL MUST be set to that of an accessible agent
1+
public extension AgentClient {
32
func listAgentDirectory(_ req: LSRequest) async throws(ClientError) -> LSResponse {
4-
let res = try await request("/api/v0/list-directory", method: .post, body: req)
3+
let res = try await client.request("/api/v0/list-directory", method: .post, body: req)
54
guard res.resp.statusCode == 200 else {
6-
throw responseAsError(res)
5+
throw client.responseAsError(res)
76
}
8-
return try decode(LSResponse.self, from: res.data)
7+
return try client.decode(LSResponse.self, from: res.data)
98
}
109
}
1110

0 commit comments

Comments
 (0)