Skip to content

Commit 584be80

Browse files
committed
enumerate statuses
1 parent 9a2026d commit 584be80

File tree

2 files changed

+125
-43
lines changed

2 files changed

+125
-43
lines changed

Coder-Desktop/VPNLib/FileSync/FileSyncSession.swift

+108-17
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public struct FileSyncSession: Identifiable {
4848
}
4949
if case .error = status {} else {
5050
if state.conflicts.count > 0 {
51-
status = .needsAttention(name: "Conflicts", desc: "The session has conflicts that need to be resolved")
51+
status = .conflicts
5252
}
5353
}
5454
self.status = status
@@ -133,11 +133,11 @@ public struct FileSyncSessionEndpointSize: Equatable {
133133

134134
public enum FileSyncStatus {
135135
case unknown
136-
case error(name: String, desc: String)
136+
case error(FileSyncErrorStatus)
137137
case ok
138138
case paused
139-
case needsAttention(name: String, desc: String)
140-
case working(name: String, desc: String)
139+
case conflicts
140+
case working(FileSyncWorkingStatus)
141141

142142
public var color: Color {
143143
switch self {
@@ -149,7 +149,7 @@ public enum FileSyncStatus {
149149
.red
150150
case .error:
151151
.red
152-
case .needsAttention:
152+
case .conflicts:
153153
.orange
154154
case .working:
155155
.purple
@@ -160,33 +160,33 @@ public enum FileSyncStatus {
160160
switch self {
161161
case .unknown:
162162
"Unknown"
163-
case let .error(name, _):
164-
"\(name)"
163+
case let .error(status):
164+
status.name
165165
case .ok:
166166
"Watching"
167167
case .paused:
168168
"Paused"
169-
case let .needsAttention(name, _):
170-
name
171-
case let .working(name, _):
172-
name
169+
case .conflicts:
170+
"Conflicts"
171+
case let .working(status):
172+
status.name
173173
}
174174
}
175175

176176
public var description: String {
177177
switch self {
178178
case .unknown:
179179
"Unknown status message."
180-
case let .error(_, desc):
181-
desc
180+
case let .error(status):
181+
status.description
182182
case .ok:
183183
"The session is watching for filesystem changes."
184184
case .paused:
185185
"The session is paused."
186-
case let .needsAttention(_, desc):
187-
desc
188-
case let .working(_, desc):
189-
desc
186+
case .conflicts:
187+
"The session has conflicts that need to be resolved."
188+
case let .working(status):
189+
status.description
190190
}
191191
}
192192

@@ -195,6 +195,97 @@ public enum FileSyncStatus {
195195
}
196196
}
197197

198+
public enum FileSyncWorkingStatus {
199+
case connectingLocal
200+
case connectingRemote
201+
case scanning
202+
case reconciling
203+
case stagingLocal
204+
case stagingRemote
205+
case transitioning
206+
case saving
207+
208+
var name: String {
209+
switch self {
210+
case .connectingLocal:
211+
return "Connecting (local)"
212+
case .connectingRemote:
213+
return "Connecting (remote)"
214+
case .scanning:
215+
return "Scanning"
216+
case .reconciling:
217+
return "Reconciling"
218+
case .stagingLocal:
219+
return "Staging (local)"
220+
case .stagingRemote:
221+
return "Staging (remote)"
222+
case .transitioning:
223+
return "Transitioning"
224+
case .saving:
225+
return "Saving"
226+
}
227+
}
228+
229+
var description: String {
230+
switch self {
231+
case .connectingLocal:
232+
return "The session is attempting to connect to the local endpoint."
233+
case .connectingRemote:
234+
return "The session is attempting to connect to the remote endpoint."
235+
case .scanning:
236+
return "The session is scanning the filesystem on each endpoint."
237+
case .reconciling:
238+
return "The session is performing reconciliation."
239+
case .stagingLocal:
240+
return "The session is staging files locally"
241+
case .stagingRemote:
242+
return "The session is staging files on the remote"
243+
case .transitioning:
244+
return "The session is performing transition operations on each endpoint."
245+
case .saving:
246+
return "The session is recording synchronization history to disk."
247+
}
248+
}
249+
}
250+
251+
public enum FileSyncErrorStatus {
252+
case disconnected
253+
case haltedOnRootEmptied
254+
case haltedOnRootDeletion
255+
case haltedOnRootTypeChange
256+
case waitingForRescan
257+
258+
var name: String {
259+
switch self {
260+
case .disconnected:
261+
return "Disconnected"
262+
case .haltedOnRootEmptied:
263+
return "Halted on root emptied"
264+
case .haltedOnRootDeletion:
265+
return "Halted on root deletion"
266+
case .haltedOnRootTypeChange:
267+
return "Halted on root type change"
268+
case .waitingForRescan:
269+
return "Waiting for rescan"
270+
}
271+
}
272+
273+
var description: String {
274+
switch self {
275+
case .disconnected:
276+
return "The session is unpaused but not currently connected or connecting to either endpoint."
277+
case .haltedOnRootEmptied:
278+
return "The session is halted due to the root emptying safety check."
279+
case .haltedOnRootDeletion:
280+
return "The session is halted due to the root deletion safety check."
281+
case .haltedOnRootTypeChange:
282+
return "The session is halted due to the root type change safety check."
283+
case .waitingForRescan:
284+
return "The session is waiting to retry scanning after an error during the previous scan."
285+
}
286+
}
287+
}
288+
198289
public enum FileSyncEndpoint {
199290
case local
200291
case remote

Coder-Desktop/VPNLib/FileSync/MutagenConvert.swift

+17-26
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,31 @@
22
func convertSessionStatus(status: Synchronization_Status) -> FileSyncStatus {
33
switch status {
44
case .disconnected:
5-
.error(name: "Disconnected",
6-
desc: "The session is unpaused but not currently connected or connecting to either endpoint.")
5+
.error(.disconnected)
76
case .haltedOnRootEmptied:
8-
.error(name: "Halted on root emptied", desc: "The session is halted due to the root emptying safety check.")
7+
.error(.haltedOnRootEmptied)
98
case .haltedOnRootDeletion:
10-
.error(name: "Halted on root deletion", desc: "The session is halted due to the root deletion safety check.")
9+
.error(.haltedOnRootDeletion)
1110
case .haltedOnRootTypeChange:
12-
.error(
13-
name: "Halted on root type change",
14-
desc: "The session is halted due to the root type change safety check."
15-
)
11+
.error(.haltedOnRootTypeChange)
1612
case .waitingForRescan:
17-
.error(name: "Waiting for rescan",
18-
desc: "The session is waiting to retry scanning after an error during the previous scan.")
19-
case .connectingAlpha:
20-
// Alpha -> Local
21-
.working(name: "Connecting (local)", desc: "The session is attempting to connect to the local endpoint.")
22-
case .connectingBeta:
23-
// Beta -> Remote
24-
.working(name: "Connecting (remote)", desc: "The session is attempting to connect to the remote endpoint.")
13+
.error(.waitingForRescan)
14+
case .connectingAlpha: // Alpha -> Local
15+
.working(.connectingLocal)
16+
case .connectingBeta: // Beta -> Remote
17+
.working(.connectingRemote)
2518
case .scanning:
26-
.working(name: "Scanning", desc: "The session is scanning the filesystem on each endpoint.")
19+
.working(.scanning)
2720
case .reconciling:
28-
.working(name: "Reconciling", desc: "The session is performing reconciliation.")
29-
case .stagingAlpha:
30-
// Alpha -> Local
31-
.working(name: "Staging (local)", desc: "The session is staging files locally")
32-
case .stagingBeta:
33-
// Beta -> Remote
34-
.working(name: "Staging (remote)", desc: "The session is staging files on the remote")
21+
.working(.reconciling)
22+
case .stagingAlpha: // Alpha -> Local
23+
.working(.stagingLocal)
24+
case .stagingBeta: // Beta -> Remote
25+
.working(.stagingRemote)
3526
case .transitioning:
36-
.working(name: "Transitioning", desc: "The session is performing transition operations on each endpoint.")
27+
.working(.transitioning)
3728
case .saving:
38-
.working(name: "Saving", desc: "The session is recording synchronization history to disk.")
29+
.working(.saving)
3930
case .watching:
4031
.ok
4132
case .UNRECOGNIZED:

0 commit comments

Comments
 (0)