Skip to content

Commit 60f8964

Browse files
committed
fix: start coder connect progress indicator immediately
1 parent 50e4a63 commit 60f8964

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

Coder-Desktop/Coder-Desktop/VPN/VPNProgress.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ struct VPNProgressView: View {
1313
var body: some View {
1414
VStack {
1515
CircularProgressView(value: value)
16-
// We estimate that the last half takes 8 seconds
16+
// We estimate the duration of the last 40%
1717
// so it doesn't appear stuck
18-
.autoComplete(threshold: 0.5, duration: 8)
18+
.autoComplete(threshold: 0.6, duration: 2.8)
19+
// We estimate the duration of the first 15% (spawning Helper)
20+
// so it doesn't appear stuck
21+
.autoStart(to: 0.15, duration: 1.8)
1922
Text(progressMessage)
2023
.multilineTextAlignment(.center)
2124
}
@@ -51,13 +54,13 @@ struct VPNProgressView: View {
5154
// 35MB if the server doesn't give us the expected size
5255
let totalBytes = downloadProgress.totalBytesToWrite ?? 35_000_000
5356
let downloadPercent = min(1.0, Float(downloadProgress.totalBytesWritten) / Float(totalBytes))
54-
return 0.4 * downloadPercent
57+
return 0.15 + (0.35 * downloadPercent)
5558
case .validating:
56-
return 0.43
59+
return 0.53
5760
case .removingQuarantine:
58-
return 0.46
61+
return 0.56
5962
case .startingTunnel:
60-
return 0.50
63+
return 0.60
6164
}
6265
}
6366
}

Coder-Desktop/Coder-Desktop/Views/CircularProgressView.swift

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ struct CircularProgressView: View {
1111
var autoCompleteThreshold: Float?
1212
var autoCompleteDuration: TimeInterval?
1313

14+
var autoStartValue: Float?
15+
var autoStartDuration: TimeInterval?
16+
17+
@State private var currentProgress: Float = 0
18+
1419
var body: some View {
1520
ZStack {
1621
if let value {
@@ -19,13 +24,23 @@ struct CircularProgressView: View {
1924
.stroke(backgroundColor, style: StrokeStyle(lineWidth: strokeWidth, lineCap: .round))
2025

2126
Circle()
22-
.trim(from: 0, to: CGFloat(displayValue(for: value)))
27+
.trim(from: 0, to: CGFloat(displayValue(for: currentProgress)))
2328
.stroke(primaryColor, style: StrokeStyle(lineWidth: strokeWidth, lineCap: .round))
2429
.rotationEffect(.degrees(-90))
25-
.animation(autoCompleteAnimation(for: value), value: value)
2630
}
2731
.frame(width: diameter, height: diameter)
28-
32+
.onAppear {
33+
if let autoStartValue, let autoStartDuration, value == 0 {
34+
withAnimation(.easeOut(duration: autoStartDuration)) {
35+
currentProgress = autoStartValue
36+
}
37+
}
38+
}
39+
.onChange(of: value) {
40+
withAnimation(currentAnimation(for: value)) {
41+
currentProgress = value
42+
}
43+
}
2944
} else {
3045
IndeterminateSpinnerView(
3146
diameter: diameter,
@@ -48,11 +63,15 @@ struct CircularProgressView: View {
4863
return value
4964
}
5065

51-
private func autoCompleteAnimation(for value: Float) -> Animation? {
66+
private func currentAnimation(for value: Float) -> Animation {
5267
guard let threshold = autoCompleteThreshold,
5368
let duration = autoCompleteDuration,
5469
value >= threshold, value < 1.0
5570
else {
71+
// Use the auto-start animation if it's running, otherwise default.
72+
if let autoStartDuration, value < (autoStartValue ?? 0) {
73+
return .easeOut(duration: autoStartDuration)
74+
}
5675
return .default
5776
}
5877

@@ -67,6 +86,13 @@ extension CircularProgressView {
6786
view.autoCompleteDuration = duration
6887
return view
6988
}
89+
90+
func autoStart(to value: Float, duration: TimeInterval) -> CircularProgressView {
91+
var view = self
92+
view.autoStartValue = value
93+
view.autoStartDuration = duration
94+
return view
95+
}
7096
}
7197

7298
// We note a constant >10% CPU usage when using a SwiftUI rotation animation that

0 commit comments

Comments
 (0)