Skip to content

fix: improve file sync agent picker #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ struct FileSyncConfig<VPN: VPNService, FS: FileSyncDaemon>: View {
// When the Window is visible, poll for session updates every
// two seconds.
while !Task.isCancelled {
if !fileSync.state.isFailed {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already checked in refreshSessions.

await fileSync.refreshSessions()
}
await fileSync.refreshSessions()
try? await Task.sleep(for: .seconds(2))
}
}.onAppear {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct FileSyncSessionModal<VPN: VPNService, FS: FileSyncDaemon>: View {
@EnvironmentObject private var fileSync: FS

@State private var localPath: String = ""
@State private var workspace: Agent?
@State private var chosenAgent: String?
@State private var remotePath: String = ""

@State private var loading: Bool = false
Expand Down Expand Up @@ -37,12 +37,12 @@ struct FileSyncSessionModal<VPN: VPNService, FS: FileSyncDaemon>: View {
}
}
Section {
Picker("Workspace", selection: $workspace) {
Picker("Workspace", selection: $chosenAgent) {
ForEach(agents, id: \.id) { agent in
Text(agent.primaryHost!).tag(agent)
Text(agent.primaryHost!).tag(agent.primaryHost!)
}
// HACK: Silence error logs for no-selection.
Divider().tag(nil as Agent?)
Divider().tag(nil as String?)
}
}
Section {
Expand All @@ -55,15 +55,16 @@ struct FileSyncSessionModal<VPN: VPNService, FS: FileSyncDaemon>: View {
Button("Cancel", action: { dismiss() }).keyboardShortcut(.cancelAction)
Button(existingSession == nil ? "Add" : "Save") { Task { await submit() }}
.keyboardShortcut(.defaultAction)
.disabled(localPath.isEmpty || remotePath.isEmpty || chosenAgent == nil)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the form unsubmittable if any of the fields are trivially invalid.

}.padding(20)
}.onAppear {
if let existingSession {
localPath = existingSession.alphaPath
workspace = agents.first { $0.primaryHost == existingSession.agentHost }
chosenAgent = agents.first { $0.primaryHost == existingSession.agentHost }?.primaryHost
remotePath = existingSession.betaPath
} else {
// Set the picker to the first agent by default
workspace = agents.first
chosenAgent = agents.first?.primaryHost
}
}.disabled(loading)
.alert("Error", isPresented: Binding(
Expand All @@ -76,7 +77,7 @@ struct FileSyncSessionModal<VPN: VPNService, FS: FileSyncDaemon>: View {

func submit() async {
createError = nil
guard let workspace else {
guard let chosenAgent else {
return
}
loading = true
Expand All @@ -87,7 +88,7 @@ struct FileSyncSessionModal<VPN: VPNService, FS: FileSyncDaemon>: View {
}
try await fileSync.createSession(
localPath: localPath,
agentHost: workspace.primaryHost!,
agentHost: chosenAgent,
remotePath: remotePath
)
} catch {
Expand Down
9 changes: 9 additions & 0 deletions Coder-Desktop/Coder-Desktop/Views/VPN/VPNMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ struct VPNMenu<VPN: VPNService, FS: FileSyncDaemon>: View {
.environmentObject(vpn)
.environmentObject(state)
.onReceive(inspection.notice) { inspection.visit(self, $0) } // ViewInspector
.task {
// If there's a file sync session error, an icon will be displayed
// next to the file sync button. The file sync window polls more
// frequently when it's open.
while !Task.isCancelled {
await fileSync.refreshSessions()
try? await Task.sleep(for: .seconds(15))
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, we were only polling if the file sync window was open. We want the user to be aware of any errors at a glance, so we need to poll even when the window is closed.

}

private var vpnDisabled: Bool {
Expand Down
Loading