From 5fc988f681716e9d96096f70399040bc79cd27c0 Mon Sep 17 00:00:00 2001 From: osy <50960678+osy@users.noreply.github.com> Date: Mon, 29 Apr 2024 17:08:15 -0700 Subject: [PATCH] config(macOS): show progress indicator for long tasks Resolves #4006 --- Platform/Shared/BusyIndicator.swift | 27 ++++++++++++++++++++++++++- Platform/Shared/BusyOverlay.swift | 2 +- Platform/UTMData.swift | 3 +++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Platform/Shared/BusyIndicator.swift b/Platform/Shared/BusyIndicator.swift index aef05d8e3..7a02d8af8 100644 --- a/Platform/Shared/BusyIndicator.swift +++ b/Platform/Shared/BusyIndicator.swift @@ -17,13 +17,38 @@ import SwiftUI struct BusyIndicator: View { + @Binding var progress: Float? + + init(progress: Binding = .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 { diff --git a/Platform/Shared/BusyOverlay.swift b/Platform/Shared/BusyOverlay.swift index ce6febdc7..17fc29129 100644 --- a/Platform/Shared/BusyOverlay.swift +++ b/Platform/Shared/BusyOverlay.swift @@ -22,7 +22,7 @@ struct BusyOverlay: View { var body: some View { Group { if data.busy { - BusyIndicator() + BusyIndicator(progress: $data.busyProgress) } else { EmptyView() } diff --git a/Platform/UTMData.swift b/Platform/UTMData.swift index f72d9e1a5..01343d802 100644 --- a/Platform/UTMData.swift +++ b/Platform/UTMData.swift @@ -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?