mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-11-09 13:10:24 +01:00
♻️ Rework site list loading UI
* 0.2 second delay for smooth UI (minimum) * > 0.5 second delay for operation = show spinner
This commit is contained in:
@@ -39,6 +39,8 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
|
|||||||
return sites[tableView.selectedRow]
|
return sites[tableView.selectedRow]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var timer: Timer? = nil
|
||||||
|
|
||||||
// MARK: - Display
|
// MARK: - Display
|
||||||
|
|
||||||
public static func create(delegate: NSWindowDelegate?) {
|
public static func create(delegate: NSWindowDelegate?) {
|
||||||
@@ -90,7 +92,11 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
|
|||||||
Also shows a spinner to indicate that we're busy.
|
Also shows a spinner to indicate that we're busy.
|
||||||
*/
|
*/
|
||||||
private func setUIBusy() {
|
private func setUIBusy() {
|
||||||
progressIndicator.startAnimation(nil)
|
// If it takes more than 0.5s to set the UI to not busy, show a spinner
|
||||||
|
timer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: false, block: { _ in
|
||||||
|
self.progressIndicator.startAnimation(true)
|
||||||
|
})
|
||||||
|
|
||||||
tableView.alphaValue = 0.3
|
tableView.alphaValue = 0.3
|
||||||
tableView.isEnabled = false
|
tableView.isEnabled = false
|
||||||
tableView.selectRowIndexes([], byExtendingSelection: true)
|
tableView.selectRowIndexes([], byExtendingSelection: true)
|
||||||
@@ -100,6 +106,7 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
|
|||||||
Re-enables the UI so the user can interact with it.
|
Re-enables the UI so the user can interact with it.
|
||||||
*/
|
*/
|
||||||
private func setUINotBusy() {
|
private func setUINotBusy() {
|
||||||
|
timer?.invalidate()
|
||||||
progressIndicator.stopAnimation(nil)
|
progressIndicator.stopAnimation(nil)
|
||||||
tableView.alphaValue = 1.0
|
tableView.alphaValue = 1.0
|
||||||
tableView.isEnabled = true
|
tableView.isEnabled = true
|
||||||
@@ -118,7 +125,9 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
|
|||||||
setUIBusy()
|
setUIBusy()
|
||||||
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
||||||
execute()
|
execute()
|
||||||
DispatchQueue.main.async { [self] in
|
|
||||||
|
// For a smoother animation, expect at least a 0.2 second delay
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { [self] in
|
||||||
completion()
|
completion()
|
||||||
setUINotBusy()
|
setUINotBusy()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user