From b43afb405fb0bfe017d2d88faa4b5bec71f1cf63 Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Wed, 20 Mar 2019 19:25:25 -0400 Subject: [PATCH] Disable the menu item during updates --- Persephone/AppDelegate.swift | 14 ++++++++++++++ Persephone/Resources/Base.lproj/Main.storyboard | 9 +++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Persephone/AppDelegate.swift b/Persephone/AppDelegate.swift index ef4a5f4..31a0e5d 100644 --- a/Persephone/AppDelegate.swift +++ b/Persephone/AppDelegate.swift @@ -26,6 +26,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, MediaKeyTapDelegate { mediaKeyTap = MediaKeyTap(delegate: self) mediaKeyTap?.start() + + NotificationCenter.default.addObserver( + self, + selector: #selector(enableUpdateDatabaseMenuItem), + name: Notification.databaseUpdateFinished, + object: AppDelegate.mpdClient + ) } func applicationWillTerminate(_ aNotification: Notification) { @@ -70,6 +77,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, MediaKeyTapDelegate { } @IBAction func updateDatabase(_ sender: NSMenuItem) { + sender.isEnabled = false AppDelegate.mpdClient.updateDatabase() } + + @objc func enableUpdateDatabaseMenuItem() { + updateDatabaseMenuItem?.isEnabled = true + } + + @IBOutlet weak var updateDatabaseMenuItem: NSMenuItem! } diff --git a/Persephone/Resources/Base.lproj/Main.storyboard b/Persephone/Resources/Base.lproj/Main.storyboard index 30ed0cd..99cca89 100644 --- a/Persephone/Resources/Base.lproj/Main.storyboard +++ b/Persephone/Resources/Base.lproj/Main.storyboard @@ -64,9 +64,10 @@ - + + @@ -118,7 +119,11 @@ - + + + + +