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

fix: start coder connect progress indicator immediately#214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ethanndickson merged 1 commit intomainfromethan/progress-auto-start
Aug 6, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletionsCoder-Desktop/Coder-Desktop/VPN/VPNProgress.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,9 +13,12 @@ struct VPNProgressView: View {
varbody:someView{
VStack{
CircularProgressView(value: value)
// We estimatethatthelast half takes 8 seconds
// We estimate theduration of the last 35%
// so it doesn't appear stuck
.autoComplete(threshold:0.5, duration:8)
.autoComplete(threshold:0.65, duration:8)
// We estimate the duration of the first 25% (spawning Helper)
// so it doesn't appear stuck
.autoStart(until:0.25, duration:2)
Text(progressMessage)
.multilineTextAlignment(.center)
}
Expand DownExpand Up@@ -46,16 +49,16 @@ struct VPNProgressView: View {
guardlet downloadProgress= progress.downloadProgresselse{
// We can't make this illegal state unrepresentable because XPC
// doesn't support enums with associated values.
return0.05
return0.15
}
// 35MB if the server doesn't give us the expected size
lettotalBytes= downloadProgress.totalBytesToWrite??35_000_000
letdownloadPercent=min(1.0,Float(downloadProgress.totalBytesWritten)/ Float(totalBytes))
return0.4* downloadPercent
return0.25+(0.35* downloadPercent)
case.validating:
return0.43
return0.63
case.startingTunnel:
return0.50
return0.65
}
}
}
59 changes: 44 additions & 15 deletionsCoder-Desktop/Coder-Desktop/Views/CircularProgressView.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,13 +3,24 @@ import SwiftUI
structCircularProgressView:View{
letvalue:Float?

varstrokeWidth:CGFloat=4
vardiameter:CGFloat=22
varstrokeWidth:CGFloat
vardiameter:CGFloat
varprimaryColor:Color=.secondary
varbackgroundColor:Color=.secondary.opacity(0.3)

varautoCompleteThreshold:Float?
varautoCompleteDuration:TimeInterval?
privatevarautoComplete:(threshold:Float, duration:TimeInterval)?
privatevarautoStart:(until:Float, duration:TimeInterval)?

@StateprivatevarcurrentProgress:Float=0

init(value:Float?=nil,
strokeWidth:CGFloat=4,
diameter:CGFloat=22)
{
self.value= value
self.strokeWidth= strokeWidth
self.diameter= diameter
}

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

Circle()
.trim(from:0, to:CGFloat(displayValue(for:value)))
.trim(from:0, to:CGFloat(displayValue(for:currentProgress)))
.stroke(primaryColor, style:StrokeStyle(lineWidth: strokeWidth, lineCap:.round))
.rotationEffect(.degrees(-90))
.animation(autoCompleteAnimation(for: value), value: value)
}
.frame(width: diameter, height: diameter)

.onAppear{
iflet autoStart, value==0{
withAnimation(.easeOut(duration: autoStart.duration)){
currentProgress= autoStart.until
}
}
}
.onChange(of: value){
withAnimation(currentAnimation(for: value)){
currentProgress= value
}
}
}else{
IndeterminateSpinnerView(
diameter: diameter,
Expand All@@ -40,31 +61,39 @@ struct CircularProgressView: View {
}

privatefunc displayValue(for value:Float)->Float{
iflet threshold=autoCompleteThreshold,
iflet threshold=autoComplete?.threshold,
value>= threshold, value<1.0
{
return1.0
}
return value
}

privatefunc autoCompleteAnimation(for value:Float)->Animation?{
guardlet threshold= autoCompleteThreshold,
let duration= autoCompleteDuration,
value>= threshold, value<1.0
privatefunc currentAnimation(for value:Float)->Animation{
guardlet autoComplete,
value>= autoComplete.threshold, value<1.0
else{
// Use the auto-start animation if it's running, otherwise default.
iflet autoStart{
return.easeOut(duration: autoStart.duration)
}
return.default
}

return.easeOut(duration: duration)
return.easeOut(duration:autoComplete.duration)
}
}

extensionCircularProgressView{
func autoComplete(threshold:Float, duration:TimeInterval)->CircularProgressView{
varview=self
view.autoCompleteThreshold= threshold
view.autoCompleteDuration= duration
view.autoComplete=(threshold: threshold, duration: duration)
return view
}

func autoStart(until value:Float, duration:TimeInterval)->CircularProgressView{
varview=self
view.autoStart=(until: value, duration: duration)
return view
}
}
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp