From 7207598cdcea203376bd4f73f317b77bef8f0a1a Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 12 Nov 2017 11:01:17 -0800 Subject: [PATCH] Close the finding-feed progress window once the feed has been found. Fix #145. --- ...ndeterminateProgressWindowController.swift | 51 +++++++++++++++---- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/Evergreen/ProgressWindow/IndeterminateProgressWindowController.swift b/Evergreen/ProgressWindow/IndeterminateProgressWindowController.swift index 644570852..b09b28894 100644 --- a/Evergreen/ProgressWindow/IndeterminateProgressWindowController.swift +++ b/Evergreen/ProgressWindow/IndeterminateProgressWindowController.swift @@ -8,7 +8,48 @@ import Cocoa -class IndeterminateProgressWindowController: NSWindowController { +func runIndeterminateProgressWithMessage(_ message: String) { + + IndeterminateProgressController.beginProgressWithMessage(message) +} + +func stopIndeterminateProgress() { + + IndeterminateProgressController.endProgress() +} + +private final class IndeterminateProgressController { + + static var windowController: IndeterminateProgressWindowController? + static var runningProgressWindow = false + + static func beginProgressWithMessage(_ message: String) { + + if runningProgressWindow { + assertionFailure("Expected !runningProgressWindow.") + endProgress() + } + + runningProgressWindow = true + windowController = IndeterminateProgressWindowController(message: message) + NSApplication.shared.runModal(for: windowController!.window!) + } + + static func endProgress() { + + if !runningProgressWindow { + assertionFailure("Expected runningProgressWindow.") + return + } + + runningProgressWindow = false + NSApplication.shared.stopModal() + windowController?.close() + windowController = nil + } +} + +private final class IndeterminateProgressWindowController: NSWindowController { @IBOutlet var messageLabel: NSTextField! @IBOutlet var progressIndicator: NSProgressIndicator! @@ -26,13 +67,5 @@ class IndeterminateProgressWindowController: NSWindowController { } } -func runIndeterminateProgressWithMessage(_ message: String) { - let windowController = IndeterminateProgressWindowController(message: message) - NSApplication.shared.runModal(for: windowController.window!) -} -func stopIndeterminateProgress() { - - NSApplication.shared.stopModal() -}