Skip to content

Commit 92b7969

Browse files
committed
fix: improve file sync agent picker
1 parent fe20801 commit 92b7969

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ struct FileSyncConfig<VPN: VPNService, FS: FileSyncDaemon>: View {
107107
// When the Window is visible, poll for session updates every
108108
// two seconds.
109109
while !Task.isCancelled {
110-
if !fileSync.state.isFailed {
111-
await fileSync.refreshSessions()
112-
}
110+
await fileSync.refreshSessions()
113111
try? await Task.sleep(for: .seconds(2))
114112
}
115113
}.onAppear {

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 chosenAgent: 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: $chosenAgent) {
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 || chosenAgent == nil)
5859
}.padding(20)
5960
}.onAppear {
6061
if let existingSession {
6162
localPath = existingSession.alphaPath
62-
workspace = agents.first { $0.primaryHost == existingSession.agentHost }
63+
chosenAgent = 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+
chosenAgent = 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 chosenAgent 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: chosenAgent,
9192
remotePath: remotePath
9293
)
9394
} catch {

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

+9
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ 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+
// If there's a file sync session error, an icon will be displayed
121+
// next to the file sync button. The file sync window polls more
122+
// frequently when it's open.
123+
while !Task.isCancelled {
124+
await fileSync.refreshSessions()
125+
try? await Task.sleep(for: .seconds(15))
126+
}
127+
}
119128
}
120129

121130
private var vpnDisabled: Bool {

0 commit comments

Comments
 (0)