diff options
Diffstat (limited to 'osdep/macos/remote_command_center.swift')
-rw-r--r-- | osdep/macos/remote_command_center.swift | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/osdep/macos/remote_command_center.swift b/osdep/macos/remote_command_center.swift index b08a726183..a5dd662737 100644 --- a/osdep/macos/remote_command_center.swift +++ b/osdep/macos/remote_command_center.swift @@ -87,14 +87,10 @@ class RemoteCommandCenter: NSObject { MPRemoteCommandCenter.shared().bookmarkCommand, ] - let application: Application - var mpInfoCenter: MPNowPlayingInfoCenter { get { return MPNowPlayingInfoCenter.default() } } var isPaused: Bool = false { didSet { updatePlaybackState() } } - @objc init(app: Application) { - application = app - + @objc override init() { super.init() for cmd in disabledCommands { @@ -110,8 +106,10 @@ class RemoteCommandCenter: NSObject { } } - if let icon = application.getMPVIcon(), #available(macOS 10.13.2, *) { - let albumArt = MPMediaItemArtwork(boundsSize:icon.size) { _ in + if let app = NSApp as? Application, let icon = app.getMPVIcon(), + #available(macOS 10.13.2, *) + { + let albumArt = MPMediaItemArtwork(boundsSize: icon.size) { _ in return icon } nowPlayingInfo[MPMediaItemPropertyArtwork] = albumArt @@ -119,6 +117,13 @@ class RemoteCommandCenter: NSObject { mpInfoCenter.nowPlayingInfo = nowPlayingInfo mpInfoCenter.playbackState = .playing + + NotificationCenter.default.addObserver( + self, + selector: #selector(self.makeCurrent), + name: NSApplication.willBecomeActiveNotification, + object: nil + ) } @objc func stop() { @@ -131,7 +136,7 @@ class RemoteCommandCenter: NSObject { mpInfoCenter.playbackState = .unknown } - @objc func makeCurrent() { + @objc func makeCurrent(notification: NSNotification) { mpInfoCenter.playbackState = .paused mpInfoCenter.playbackState = .playing updatePlaybackState() @@ -160,7 +165,7 @@ class RemoteCommandCenter: NSObject { } } - application.handleMPKey(mpKey, withMask: Int32(state)); + EventsResponder.sharedInstance().handleMPKey(mpKey, withMask: Int32(state)) return .success } |