Skip to content

Commit 9f625fd

Browse files
fix: improve file sync agent picker (#128)
Previously, the agent/workspace picker when creating a file sync session had the user choose between instances of the `Agent` struct. This meant the value would get unselected were the status of the agent to change. I'm not sure why I had the picker select the entire struct instead of just the hostname.
1 parent fe20801 commit 9f625fd

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

Coder-Desktop/Coder-Desktop/Views/FileSync/FileSyncConfig.swift

-9
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,6 @@ struct FileSyncConfig<VPN: VPNService, FS: FileSyncDaemon>: View {
103103
// Opens the log file in Console
104104
NSWorkspace.shared.open(fileSync.logFile)
105105
}
106-
}.task {
107-
// When the Window is visible, poll for session updates every
108-
// two seconds.
109-
while !Task.isCancelled {
110-
if !fileSync.state.isFailed {
111-
await fileSync.refreshSessions()
112-
}
113-
try? await Task.sleep(for: .seconds(2))
114-
}
115106
}.onAppear {
116107
isVisible = true
117108
}.onDisappear {

Coder-Desktop/Coder-Desktop/Views/FileSync/FileSyncSessionModal.swift

+9-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct FileSyncSessionModal<VPN: VPNService, FS: FileSyncDaemon>: View {
88
@EnvironmentObject private var fileSync: FS
99

1010
@State private var localPath: String = ""
11-
@State private var workspace: Agent?
11+
@State private var remoteHostname: String?
1212
@State private var remotePath: String = ""
1313

1414
@State private var loading: Bool = false
@@ -37,12 +37,12 @@ struct FileSyncSessionModal<VPN: VPNService, FS: FileSyncDaemon>: View {
3737
}
3838
}
3939
Section {
40-
Picker("Workspace", selection: $workspace) {
40+
Picker("Workspace", selection: $remoteHostname) {
4141
ForEach(agents, id: \.id) { agent in
42-
Text(agent.primaryHost!).tag(agent)
42+
Text(agent.primaryHost!).tag(agent.primaryHost!)
4343
}
4444
// HACK: Silence error logs for no-selection.
45-
Divider().tag(nil as Agent?)
45+
Divider().tag(nil as String?)
4646
}
4747
}
4848
Section {
@@ -55,15 +55,16 @@ struct FileSyncSessionModal<VPN: VPNService, FS: FileSyncDaemon>: View {
5555
Button("Cancel", action: { dismiss() }).keyboardShortcut(.cancelAction)
5656
Button(existingSession == nil ? "Add" : "Save") { Task { await submit() }}
5757
.keyboardShortcut(.defaultAction)
58+
.disabled(localPath.isEmpty || remotePath.isEmpty || remoteHostname == nil)
5859
}.padding(20)
5960
}.onAppear {
6061
if let existingSession {
6162
localPath = existingSession.alphaPath
62-
workspace = agents.first { $0.primaryHost == existingSession.agentHost }
63+
remoteHostname = agents.first { $0.primaryHost == existingSession.agentHost }?.primaryHost
6364
remotePath = existingSession.betaPath
6465
} else {
6566
// Set the picker to the first agent by default
66-
workspace = agents.first
67+
remoteHostname = agents.first?.primaryHost
6768
}
6869
}.disabled(loading)
6970
.alert("Error", isPresented: Binding(
@@ -76,7 +77,7 @@ struct FileSyncSessionModal<VPN: VPNService, FS: FileSyncDaemon>: View {
7677

7778
func submit() async {
7879
createError = nil
79-
guard let workspace else {
80+
guard let remoteHostname else {
8081
return
8182
}
8283
loading = true
@@ -87,7 +88,7 @@ struct FileSyncSessionModal<VPN: VPNService, FS: FileSyncDaemon>: View {
8788
}
8889
try await fileSync.createSession(
8990
localPath: localPath,
90-
agentHost: workspace.primaryHost!,
91+
agentHost: remoteHostname,
9192
remotePath: remotePath
9293
)
9394
} catch {

Coder-Desktop/Coder-Desktop/Views/VPN/VPNMenu.swift

+6
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ struct VPNMenu<VPN: VPNService, FS: FileSyncDaemon>: View {
116116
.environmentObject(vpn)
117117
.environmentObject(state)
118118
.onReceive(inspection.notice) { inspection.visit(self, $0) } // ViewInspector
119+
.task {
120+
while !Task.isCancelled {
121+
await fileSync.refreshSessions()
122+
try? await Task.sleep(for: .seconds(2))
123+
}
124+
}
119125
}
120126

121127
private var vpnDisabled: Bool {

0 commit comments

Comments
 (0)