From 85b0db3baaa9f7c5dd19130b64d95187518b5fa7 Mon Sep 17 00:00:00 2001 From: NanoSector Date: Sat, 13 Mar 2021 20:56:24 +0100 Subject: [PATCH] Add spinner on refresh --- Brewed/Model/ManagedServices.swift | 5 +++++ Brewed/View/ContentView.swift | 4 ++++ Brewed/View/ServiceRow.swift | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Brewed/Model/ManagedServices.swift b/Brewed/Model/ManagedServices.swift index e28fb4a..6eec52c 100644 --- a/Brewed/Model/ManagedServices.swift +++ b/Brewed/Model/ManagedServices.swift @@ -11,6 +11,8 @@ class ManagedServices: ObservableObject, FileMonitorDelegate { @Published var services: [Service] = [] + @Published var refreshing = false + private var monitors: [URL: FileMonitor] = [:] func update(service: Service) { @@ -26,6 +28,7 @@ class ManagedServices: ObservableObject, FileMonitorDelegate { } func refresh() { + refreshing = true ListServicesCommand().exec() .done { services in self.monitors.removeAll() @@ -41,6 +44,8 @@ class ManagedServices: ObservableObject, FileMonitorDelegate { monitor.delegate = self } } + }.ensure { + self.refreshing = false }.cauterize() } diff --git a/Brewed/View/ContentView.swift b/Brewed/View/ContentView.swift index ef695a4..fde26b9 100644 --- a/Brewed/View/ContentView.swift +++ b/Brewed/View/ContentView.swift @@ -34,6 +34,10 @@ struct ContentView: View { ) } .toolbar { + if managedServices.refreshing { + ProgressView().controlSize(.small) + } + Button(action: { managedServices.refresh() }) { diff --git a/Brewed/View/ServiceRow.swift b/Brewed/View/ServiceRow.swift index b1a59e6..d4b0e9b 100644 --- a/Brewed/View/ServiceRow.swift +++ b/Brewed/View/ServiceRow.swift @@ -67,7 +67,7 @@ struct ServiceRow: View { } } } - }.disabled(executingCommand) + }.disabled(executingCommand || managedServices.refreshing) } func run() {