Skip to content

Commit 6783171

Browse files
committed
pausing & unpausing
1 parent b0a52f8 commit 6783171

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 9 additions & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 34 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy