Skip to content

Commit

Permalink
config(macOS): show progress indicator for long tasks
Browse files Browse the repository at this point in the history
Resolves #4006
  • Loading branch information
osy committed Apr 30, 2024
1 parent 7267f52 commit 5fc988f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
27 changes: 26 additions & 1 deletion Platform/Shared/BusyIndicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,38 @@
import SwiftUI

struct BusyIndicator: View {
@Binding var progress: Float?

init(progress: Binding<Float?> = .constant(nil)) {
_progress = progress
}

var body: some View {
Spinner(size: .large)
progressView
.frame(width: 100, height: 100, alignment: .center)
.foregroundColor(.white)
.background(Color.gray.opacity(0.5))
.clipShape(RoundedRectangle(cornerRadius: 25.0, style: .continuous))
}

#if os(macOS)
@ViewBuilder
private var progressView: some View {
if let progress = progress {
ProgressView(value: progress)
.progressViewStyle(.circular)
.controlSize(.large)
} else {
Spinner(size: .large)
}
}
#else
// TODO: implement progress spinner for iOS
@ViewBuilder
private var progressView: some View {
Spinner(size: .large)
}
#endif
}

struct BusyIndicator_Previews: PreviewProvider {
Expand Down
2 changes: 1 addition & 1 deletion Platform/Shared/BusyOverlay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct BusyOverlay: View {
var body: some View {
Group {
if data.busy {
BusyIndicator()
BusyIndicator(progress: $data.busyProgress)
} else {
EmptyView()
}
Expand Down
3 changes: 3 additions & 0 deletions Platform/UTMData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ struct AlertMessage: Identifiable {
/// View: show busy spinner
@Published var busy: Bool

/// View: show a percent progress in the busy spinner
@Published var busyProgress: Float?

/// View: currently selected VM
@Published var selectedVM: VMData?

Expand Down

0 comments on commit 5fc988f

Please sign in to comment.