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 3 commits
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 @@ -103,15 +103,6 @@ struct FileSyncConfig<VPN: VPNService, FS: FileSyncDaemon>: View {
// Opens the log file in Console
NSWorkspace.shared.open(fileSync.logFile)
}
}.task {
// 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()
}
try? await Task.sleep(for: .seconds(2))
}
}.onAppear {
isVisible = true
}.onDisappear {
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 remoteHostName: 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: $remoteHostName) {
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 || remoteHostName == nil)
}.padding(20)
}.onAppear {
if let existingSession {
localPath = existingSession.alphaPath
workspace = agents.first { $0.primaryHost == existingSession.agentHost }
remoteHostName = agents.first { $0.primaryHost == existingSession.agentHost }?.primaryHost
remotePath = existingSession.betaPath
} else {
// Set the picker to the first agent by default
workspace = agents.first
remoteHostName = 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 remoteHostName 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: remoteHostName,
remotePath: remotePath
)
} catch {
Expand Down
6 changes: 6 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,12 @@ struct VPNMenu<VPN: VPNService, FS: FileSyncDaemon>: View {
.environmentObject(vpn)
.environmentObject(state)
.onReceive(inspection.notice) { inspection.visit(self, $0) } // ViewInspector
.task {
while !Task.isCancelled {
await fileSync.refreshSessions()
try? await Task.sleep(for: .seconds(2))
}
}
}

private var vpnDisabled: Bool {
Expand Down
Loading