Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit84e4daa

Browse files
committed
chore: create & delete sync sessions over gRPC
1 parentc11bc07 commit84e4daa

File tree

2 files changed

+81
-46
lines changed

2 files changed

+81
-46
lines changed

‎Coder-Desktop/VPNLib/FileSync/FileSyncDaemon.swift

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public class MutagenDaemon: FileSyncDaemon {
162162
// Already connected
163163
return
164164
}
165-
group=MultiThreadedEventLoopGroup(numberOfThreads:1)
165+
group=MultiThreadedEventLoopGroup(numberOfThreads:2)
166166
do{
167167
channel=tryGRPCChannelPool.with(
168168
target:.unixDomainSocket(mutagenDaemonSocket.path),
@@ -252,51 +252,6 @@ public class MutagenDaemon: FileSyncDaemon {
252252
logger.info("\(line, privacy:.public)")
253253
}
254254
}
255-
256-
publicfunc refreshSessions()async{
257-
guard case.running= stateelse{return}
258-
// TODO: Implement
259-
}
260-
261-
publicfunc createSession(
262-
localPath _:String,
263-
agentHost _:String,
264-
remotePath _:String
265-
)asyncthrows(DaemonError){
266-
if case.stopped= state{
267-
dothrows(DaemonError){
268-
tryawaitstart()
269-
} catch{
270-
state=.failed(error)
271-
throw error
272-
}
273-
}
274-
// TODO: Add session
275-
}
276-
277-
publicfunc deleteSessions(ids _:[String])asyncthrows(DaemonError){
278-
// TODO: Delete session
279-
awaitstopIfNoSessions()
280-
}
281-
282-
privatefunc stopIfNoSessions()async{
283-
letsessions:Synchronization_ListResponse
284-
do{
285-
sessions=tryawait client!.sync.list(Synchronization_ListRequest.with{ reqin
286-
req.selection=.with{ selectionin
287-
selection.all=true
288-
}
289-
})
290-
}catch{
291-
state=.failed(.daemonStartFailure(error))
292-
return
293-
}
294-
// If there's no configured sessions, the daemon doesn't need to be running
295-
if sessions.sessionStates.isEmpty{
296-
logger.info("No sync sessions found")
297-
awaitstop()
298-
}
299-
}
300255
}
301256

302257
structDaemonClient{
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
publicextensionMutagenDaemon{
2+
func refreshSessions()async{
3+
guard case.running= stateelse{return}
4+
letsessions:Synchronization_ListResponse
5+
do{
6+
sessions=tryawait client!.sync.list(Synchronization_ListRequest.with{ reqin
7+
req.selection=.with{ selectionin
8+
selection.all=true
9+
}
10+
})
11+
}catch{
12+
state=.failed(.grpcFailure(error))
13+
return
14+
}
15+
sessionState= sessions.sessionStates.map{FileSyncSession(state: $0)}
16+
if sessionState.isEmpty{
17+
logger.info("No sync sessions found")
18+
awaitstop()
19+
}
20+
}
21+
22+
func createSession(
23+
localPath:String,
24+
agentHost:String,
25+
remotePath:String
26+
)asyncthrows(DaemonError){
27+
if case.stopped= state{
28+
dothrows(DaemonError){
29+
tryawaitstart()
30+
} catch{
31+
state=.failed(error)
32+
throw error
33+
}
34+
}
35+
let(stream, promptID)=tryawaithost()
36+
defer{ stream.cancel()}
37+
letreq=Synchronization_CreateRequest.with{ reqin
38+
req.prompter= promptID
39+
req.specification=.with{ specin
40+
spec.alpha=.with{ alphain
41+
alpha.protocol=.local
42+
alpha.path= localPath
43+
}
44+
spec.beta=.with{ betain
45+
beta.protocol=.ssh
46+
beta.host= agentHost
47+
beta.path= remotePath
48+
}
49+
// TODO: Ingest a config from somewhere
50+
spec.configuration=Synchronization_Configuration()
51+
spec.configurationAlpha=Synchronization_Configuration()
52+
spec.configurationBeta=Synchronization_Configuration()
53+
}
54+
}
55+
do{
56+
_=tryawait client!.sync.create(req)
57+
}catch{
58+
throw.grpcFailure(error)
59+
}
60+
awaitrefreshSessions()
61+
}
62+
63+
func deleteSessions(ids:[String])asyncthrows(DaemonError){
64+
// Terminating sessions does not require prompting
65+
let(stream, promptID)=tryawaithost(allowPrompts:false)
66+
defer{ stream.cancel()}
67+
guard case.running= stateelse{return}
68+
do{
69+
_=tryawait client!.sync.terminate(Synchronization_TerminateRequest.with{ reqin
70+
req.prompter= promptID
71+
req.selection=.with{ selectionin
72+
selection.specifications= ids
73+
}
74+
})
75+
}catch{
76+
throw.grpcFailure(error)
77+
}
78+
awaitrefreshSessions()
79+
}
80+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp