-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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? | ||
ethanndickson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@State private var remotePath: String = "" | ||
|
||
@State private var loading: Bool = false | ||
|
@@ -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 { | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
|
@@ -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 | ||
|
@@ -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 { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,6 +116,15 @@ struct VPNMenu<VPN: VPNService, FS: FileSyncDaemon>: View { | |
.environmentObject(vpn) | ||
.environmentObject(state) | ||
.onReceive(inspection.notice) { inspection.visit(self, $0) } // ViewInspector | ||
.task { | ||
ethanndickson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// 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)) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
There was a problem hiding this comment.
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
.