Skip to content

Commit 42096fd

Browse files
committed
pausing & unpausing
1 parent 0030ebe commit 42096fd

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

Coder-Desktop/Coder-Desktop/Preview Content/PreviewFileSync.swift

+4
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ final class PreviewFileSync: FileSyncDaemon {
2121
func createSession(localPath _: String, agentHost _: String, remotePath _: String) async throws(DaemonError) {}
2222

2323
func deleteSessions(ids _: [String]) async throws(VPNLib.DaemonError) {}
24+
25+
func pauseSessions(ids _: [String]) async throws(VPNLib.DaemonError) {}
26+
27+
func resumeSessions(ids _: [String]) async throws(VPNLib.DaemonError) {}
2428
}

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,15 @@ struct FileSyncConfig<VPN: VPNService, FS: FileSyncDaemon>: View {
6565
if let selectedSession = fileSync.sessionState.first(where: { $0.id == selection }) {
6666
Divider()
6767
Button {
68-
// TODO: Pause & Unpause
68+
Task {
69+
// TODO: Support pausing & resuming multiple selections
70+
switch selectedSession.status {
71+
case .paused:
72+
try await fileSync.resumeSessions(ids: [selectedSession.id])
73+
default:
74+
try await fileSync.pauseSessions(ids: [selectedSession.id])
75+
}
76+
}
6977
} label: {
7078
switch selectedSession.status {
7179
case .paused:

Coder-Desktop/VPNLib/FileSync/FileSyncDaemon.swift

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public protocol FileSyncDaemon: ObservableObject {
1515
func refreshSessions() async
1616
func createSession(localPath: String, agentHost: String, remotePath: String) async throws(DaemonError)
1717
func deleteSessions(ids: [String]) async throws(DaemonError)
18+
func pauseSessions(ids: [String]) async throws(DaemonError)
19+
func resumeSessions(ids: [String]) async throws(DaemonError)
1820
}
1921

2022
@MainActor

Coder-Desktop/VPNLib/FileSync/FileSyncManagement.swift

+34
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,38 @@ public extension MutagenDaemon {
7777
}
7878
await refreshSessions()
7979
}
80+
81+
func pauseSessions(ids: [String]) async throws(DaemonError) {
82+
let (stream, promptID) = try await host()
83+
defer { stream.cancel() }
84+
guard case .running = state else { return }
85+
do {
86+
_ = try await client!.sync.pause(Synchronization_PauseRequest.with { req in
87+
req.prompter = promptID
88+
req.selection = .with { selection in
89+
selection.specifications = ids
90+
}
91+
})
92+
} catch {
93+
throw .grpcFailure(error)
94+
}
95+
await refreshSessions()
96+
}
97+
98+
func resumeSessions(ids: [String]) async throws(DaemonError) {
99+
let (stream, promptID) = try await host()
100+
defer { stream.cancel() }
101+
guard case .running = state else { return }
102+
do {
103+
_ = try await client!.sync.resume(Synchronization_ResumeRequest.with { req in
104+
req.prompter = promptID
105+
req.selection = .with { selection in
106+
selection.specifications = ids
107+
}
108+
})
109+
} catch {
110+
throw .grpcFailure(error)
111+
}
112+
await refreshSessions()
113+
}
80114
}

0 commit comments

Comments
 (0)