Skip to content

Commit

Permalink
Deinit menu bar lyrics when disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelRow authored and MichaelRow committed Dec 26, 2015
1 parent 2264304 commit d8a0d5d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 11 additions & 6 deletions Lyrics/AppController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class AppController: NSObject {
}

deinit {
NSStatusBar.systemStatusBar().removeStatusItem(statusItem)
NSNotificationCenter.defaultCenter().removeObserver(self)
NSDistributedNotificationCenter.defaultCenter().removeObserver(self)
}
Expand Down Expand Up @@ -190,8 +191,9 @@ class AppController: NSObject {

@IBAction func enableMenuBarLyrics(sender:AnyObject?) {
if (sender as! NSMenuItem).state == NSOnState {
menuBarLyrics.displayLyrics(nil)
menuBarLyrics = nil
} else {
menuBarLyrics = MenuBarLyrics()
menuBarLyrics.displayLyrics(currentLyrics as String)
}
}
Expand Down Expand Up @@ -426,7 +428,9 @@ class AppController: NSObject {
self.currentLyrics = nil
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.lyricsWindow.displayLyrics(nil, secondLyrics: nil)
self.menuBarLyrics.displayLyrics(nil)
if self.menuBarLyrics != nil {
self.menuBarLyrics.displayLyrics(nil)
}
})
}
NSLog("iTunes Paused")
Expand Down Expand Up @@ -679,7 +683,7 @@ class AppController: NSObject {
self.lyricsWindow.displayLyrics(nil, secondLyrics: nil)
})
}
if userDefaults.boolForKey(LyricsMenuBarLyricsEnabled) {
if menuBarLyrics != nil {
menuBarLyrics.displayLyrics(nil)
}
}
Expand All @@ -699,7 +703,7 @@ class AppController: NSObject {
self.lyricsWindow.displayLyrics(self.currentLyrics, secondLyrics: secondLyrics)
})
}
if userDefaults.boolForKey(LyricsMenuBarLyricsEnabled) {
if menuBarLyrics != nil {
menuBarLyrics.displayLyrics(currentLyrics as String)
}
}
Expand All @@ -715,7 +719,7 @@ class AppController: NSObject {
self.lyricsWindow.displayLyrics(self.currentLyrics, secondLyrics: nil)
})
}
if userDefaults.boolForKey(LyricsMenuBarLyricsEnabled) {
if menuBarLyrics != nil {
menuBarLyrics.displayLyrics(currentLyrics as String)
}
}
Expand Down Expand Up @@ -964,13 +968,14 @@ class AppController: NSObject {
if isDesktopLyricsOn && isMenuBarLyricsOn {
userDefaults.setBool(false, forKey: LyricsMenuBarLyricsEnabled)
MessageWindowController.sharedMsgWindow.displayMessage(NSLocalizedString("DESKTOP_ON", comment: ""))
menuBarLyrics.displayLyrics(nil)
menuBarLyrics = nil
}
else if isDesktopLyricsOn && !isMenuBarLyricsOn {
userDefaults.setBool(false, forKey: LyricsDesktopLyricsEnabled)
userDefaults.setBool(true, forKey: LyricsMenuBarLyricsEnabled)
MessageWindowController.sharedMsgWindow.displayMessage(NSLocalizedString("MENU_BAR_ON", comment: ""))
lyricsWindow.displayLyrics(nil, secondLyrics: nil)
menuBarLyrics = MenuBarLyrics()
menuBarLyrics.displayLyrics(currentLyrics as String)
}
else {
Expand Down
1 change: 1 addition & 0 deletions Lyrics/MenuBarLyrics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class MenuBarLyrics: NSObject {
}

deinit {
NSStatusBar.systemStatusBar().removeStatusItem(statusItem)
NSLog("Deint StatusBarLyrics")
}

Expand Down

0 comments on commit d8a0d5d

Please sign in to comment.