Skip to content

Commit e83ac60

Browse files
committed
pausing & unpausing
1 parent 3edc849 commit e83ac60

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
@@ -59,7 +59,15 @@ struct FileSyncConfig<VPN: VPNService, FS: FileSyncDaemon>: View {
5959
if let selectedSession = fileSync.sessionState.first(where: { $0.id == selection }) {
6060
Divider()
6161
Button {
62-
// TODO: Pause & Unpause
62+
Task {
63+
// TODO: Support pausing & resuming multiple selections
64+
switch selectedSession.status {
65+
case .paused:
66+
try await fileSync.resumeSessions(ids: [selectedSession.id])
67+
default:
68+
try await fileSync.pauseSessions(ids: [selectedSession.id])
69+
}
70+
}
6371
} label: {
6472
switch selectedSession.status {
6573
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