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

Commit0dc424c

Browse files
committed
fix: start coder connect progress indicator immediately
1 parent62c3d0a commit0dc424c

File tree

2 files changed

+53
-21
lines changed

2 files changed

+53
-21
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
varbody:someView{
1414
VStack{
1515
CircularProgressView(value: value)
16-
// We estimatethatthelast half takes 8 seconds
16+
// We estimate theduration of the last 35%
1717
// so it doesn't appear stuck
18-
.autoComplete(threshold:0.5, duration:8)
18+
.autoComplete(threshold:0.65, duration:8)
19+
// We estimate the duration of the first 25% (spawning Helper)
20+
// so it doesn't appear stuck
21+
.autoStart(until:0.25, duration:2)
1922
Text(progressMessage)
2023
.multilineTextAlignment(.center)
2124
}
@@ -46,16 +49,16 @@ struct VPNProgressView: View {
4649
guardlet downloadProgress= progress.downloadProgresselse{
4750
// We can't make this illegal state unrepresentable because XPC
4851
// doesn't support enums with associated values.
49-
return0.05
52+
return0.15
5053
}
5154
// 35MB if the server doesn't give us the expected size
5255
lettotalBytes= downloadProgress.totalBytesToWrite??35_000_000
5356
letdownloadPercent=min(1.0,Float(downloadProgress.totalBytesWritten)/ Float(totalBytes))
54-
return0.4* downloadPercent
57+
return0.25+(0.35* downloadPercent)
5558
case.validating:
56-
return0.43
59+
return0.63
5760
case.startingTunnel:
58-
return0.50
61+
return0.65
5962
}
6063
}
6164
}

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

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,24 @@ import SwiftUI
33
structCircularProgressView:View{
44
letvalue:Float?
55

6-
varstrokeWidth:CGFloat=4
7-
vardiameter:CGFloat=22
6+
varstrokeWidth:CGFloat
7+
vardiameter:CGFloat
88
varprimaryColor:Color=.secondary
99
varbackgroundColor:Color=.secondary.opacity(0.3)
1010

11-
varautoCompleteThreshold:Float?
12-
varautoCompleteDuration:TimeInterval?
11+
privatevarautoComplete:(threshold:Float, duration:TimeInterval)?
12+
privatevarautoStart:(until:Float, duration:TimeInterval)?
13+
14+
@StateprivatevarcurrentProgress:Float=0
15+
16+
init(value:Float?=nil,
17+
strokeWidth:CGFloat=4,
18+
diameter:CGFloat=22)
19+
{
20+
self.value= value
21+
self.strokeWidth= strokeWidth
22+
self.diameter= diameter
23+
}
1324

1425
varbody:someView{
1526
ZStack{
@@ -19,13 +30,23 @@ struct CircularProgressView: View {
1930
.stroke(backgroundColor, style:StrokeStyle(lineWidth: strokeWidth, lineCap:.round))
2031

2132
Circle()
22-
.trim(from:0, to:CGFloat(displayValue(for:value)))
33+
.trim(from:0, to:CGFloat(displayValue(for:currentProgress)))
2334
.stroke(primaryColor, style:StrokeStyle(lineWidth: strokeWidth, lineCap:.round))
2435
.rotationEffect(.degrees(-90))
25-
.animation(autoCompleteAnimation(for: value), value: value)
2636
}
2737
.frame(width: diameter, height: diameter)
28-
38+
.onAppear{
39+
iflet autoStart, value==0{
40+
withAnimation(.easeOut(duration: autoStart.duration)){
41+
currentProgress= autoStart.until
42+
}
43+
}
44+
}
45+
.onChange(of: value){
46+
withAnimation(currentAnimation(for: value)){
47+
currentProgress= value
48+
}
49+
}
2950
}else{
3051
IndeterminateSpinnerView(
3152
diameter: diameter,
@@ -40,31 +61,39 @@ struct CircularProgressView: View {
4061
}
4162

4263
privatefunc displayValue(for value:Float)->Float{
43-
iflet threshold=autoCompleteThreshold,
64+
iflet threshold=autoComplete?.threshold,
4465
value>= threshold, value<1.0
4566
{
4667
return1.0
4768
}
4869
return value
4970
}
5071

51-
privatefunc autoCompleteAnimation(for value:Float)->Animation?{
52-
guardlet threshold= autoCompleteThreshold,
53-
let duration= autoCompleteDuration,
54-
value>= threshold, value<1.0
72+
privatefunc currentAnimation(for value:Float)->Animation{
73+
guardlet autoComplete,
74+
value>= autoComplete.threshold, value<1.0
5575
else{
76+
// Use the auto-start animation if it's running, otherwise default.
77+
iflet autoStart{
78+
return.easeOut(duration: autoStart.duration)
79+
}
5680
return.default
5781
}
5882

59-
return.easeOut(duration: duration)
83+
return.easeOut(duration:autoComplete.duration)
6084
}
6185
}
6286

6387
extensionCircularProgressView{
6488
func autoComplete(threshold:Float, duration:TimeInterval)->CircularProgressView{
6589
varview=self
66-
view.autoCompleteThreshold= threshold
67-
view.autoCompleteDuration= duration
90+
view.autoComplete=(threshold: threshold, duration: duration)
91+
return view
92+
}
93+
94+
func autoStart(until value:Float, duration:TimeInterval)->CircularProgressView{
95+
varview=self
96+
view.autoStart=(until: value, duration: duration)
6897
return view
6998
}
7099
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp