From d8fc857d23d7f60d3e331ef0c823e9c6de77ea18 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Sun, 5 Dec 2021 04:14:55 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Show=20spinner=20when=20busy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon/AppDelegate.swift | 9 ++++++ phpmon/Domain/Core/Base.lproj/Main.storyboard | 30 +++++++++++++++---- phpmon/Domain/SiteList/SiteListVC.swift | 30 +++++++++++++------ 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/phpmon/AppDelegate.swift b/phpmon/AppDelegate.swift index fbf2ef4..5a33909 100644 --- a/phpmon/AppDelegate.swift +++ b/phpmon/AppDelegate.swift @@ -73,4 +73,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele self.menu.startup() } + // MARK: - Menu Interactions + + @IBAction func reloadSiteListPressed(_ sender: Any) { + let vc = App.shared.siteListWindowController?.window?.contentViewController as? SiteListVC + if vc != nil { + vc!.reloadSites() + } + } + } diff --git a/phpmon/Domain/Core/Base.lproj/Main.storyboard b/phpmon/Domain/Core/Base.lproj/Main.storyboard index b2fcefb..e76f007 100644 --- a/phpmon/Domain/Core/Base.lproj/Main.storyboard +++ b/phpmon/Domain/Core/Base.lproj/Main.storyboard @@ -45,6 +45,18 @@ + + + + + + + + + + + + @@ -286,7 +298,7 @@ - + @@ -574,17 +586,17 @@ Gw - + - + - + - + @@ -720,21 +732,27 @@ Gw + + + + + + - + diff --git a/phpmon/Domain/SiteList/SiteListVC.swift b/phpmon/Domain/SiteList/SiteListVC.swift index bb2f816..d02ddaa 100644 --- a/phpmon/Domain/SiteList/SiteListVC.swift +++ b/phpmon/Domain/SiteList/SiteListVC.swift @@ -15,6 +15,7 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource { // MARK: - Outlets @IBOutlet weak var tableView: NSTableView! + @IBOutlet weak var progressIndicator: NSProgressIndicator! // MARK: - Variables @@ -64,21 +65,32 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource { } self.sites = Valet.shared.sites + self.progressIndicator.stopAnimation(nil) } - - // MARK: - Site Data Loading func reloadSites() { - // Reload site information - Valet.shared.reloadSites() + // Start spinner and reset view (no items) + self.progressIndicator.startAnimation(nil) + self.sites = [] + self.tableView.reloadData() - // Update the site list - self.sites = Valet.shared.sites - - // Re-apply any existing search - self.searchedFor(text: lastSearchedFor) + DispatchQueue.global(qos: .userInitiated).async { [unowned self] in + // Reload site information + Valet.shared.reloadSites() + + DispatchQueue.main.async { [self] in + // Update the site list + self.sites = Valet.shared.sites + + // Stop spinner + self.progressIndicator.stopAnimation(nil) + + // Re-apply any existing search + self.searchedFor(text: lastSearchedFor) + } + } } // MARK: - Table View