Skip to content

Commit

Permalink
Switch to a forked version of MediaKeyTap
Browse files Browse the repository at this point in the history
The previous solution of sending out activation notifications was not
really a functional one and other applications might steal focus away
from kmbmpdc without of it ever regaining it. In order to fix this, the
application is made to use a custom forked version of MediaKeyTap that
can manually set itself as the top application on the listener stack.
  • Loading branch information
arttuperala committed Feb 9, 2017
1 parent 6344cc3 commit 4d55156
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log

## [Unreleased]
### Changed
- MediaKeyTap switched a forked version to manually update kmbmpdc as the active listener application

### Fixed
- Pressing any of the menubar buttons now properly sets kmbmpdc as the active listener

## [1.1.0] - 2017-01-29
### Added
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "nhurden/MediaKeyTap"
github "arttuperala/MediaKeyTap" "master"
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "nhurden/MediaKeyTap" "1.0.0"
github "arttuperala/MediaKeyTap" "f5e37a6ba36e405145c69ef06b3c39cc668a8f97"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The following priority is used for cover art images:

* [imeji](https://github.com/arttuperala/imeji)
* [libmpdclient](https://www.musicpd.org/libs/libmpdclient/)
* [MediaKeyTap](https://github.com/nhurden/MediaKeyTap)
* forked [MediaKeyTap](https://github.com/arttuperala/MediaKeyTap)

#### Requirements

Expand Down
12 changes: 4 additions & 8 deletions kmbmpdc/Controls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class Controls: NSViewController, MediaKeyTapDelegate {
// active listener applications exit.
mediaKeyTap = MediaKeyTap(delegate: self)
mediaKeyTap?.start()
let notification = Notification(name: NSNotification.Name.NSWorkspaceDidActivateApplication)
NotificationCenter.default.post(notification)
mediaKeyTap?.activate()

// Set the button images to templates to play nice with dark mode.
playPauseButton.image?.isTemplate = true
Expand Down Expand Up @@ -122,8 +121,7 @@ class Controls: NSViewController, MediaKeyTapDelegate {
}

@IBAction func menuWasClicked(_ sender: AnyObject) {
let notification = Notification(name: NSNotification.Name.NSWorkspaceDidActivateApplication)
NotificationCenter.default.post(notification)
mediaKeyTap?.activate()

guard let delegate = appDelegate else {
return
Expand All @@ -134,8 +132,7 @@ class Controls: NSViewController, MediaKeyTapDelegate {
}

@IBAction func nextWasClicked(_ sender: AnyObject) {
let notification = Notification(name: NSNotification.Name.NSWorkspaceDidActivateApplication)
NotificationCenter.default.post(notification)
mediaKeyTap?.activate()

if MPDController.sharedController.connected {
MPDController.sharedController.next()
Expand All @@ -154,8 +151,7 @@ class Controls: NSViewController, MediaKeyTapDelegate {
}

@IBAction func playPauseWasClicked(_ sender: AnyObject) {
let notification = Notification(name: NSNotification.Name.NSWorkspaceDidActivateApplication)
NotificationCenter.default.post(notification)
mediaKeyTap?.activate()

if MPDController.sharedController.connected {
MPDController.sharedController.playPause()
Expand Down

0 comments on commit 4d55156

Please sign in to comment.