1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00

Send desktop notifications on track or state change

This commit is contained in:
Daniel Barber 2019-04-14 19:33:10 -04:00
parent a52ba06a08
commit e441d7b0d6
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
3 changed files with 19 additions and 2 deletions

View File

@ -47,6 +47,20 @@ class QueueViewController: NSViewController,
else { return }
dataSource.setQueueIcon(state)
notifyTrack()
}
func notifyTrack() {
guard let currentSong = dataSource.currentSong,
let status = AppDelegate.mpdClient.status,
status.state == .playing
else { return }
let notification = NSUserNotification()
notification.title = currentSong.title
notification.subtitle = "\(currentSong.artist)\(currentSong.album.title)"
NSUserNotificationCenter.default.deliver(notification)
}
@objc func queueChanged(_ notification: Notification) {

View File

@ -11,6 +11,7 @@ import Cocoa
class QueueDataSource: NSObject, NSOutlineViewDataSource {
var queue: [QueueItem] = []
var queuePos: Int = -1
var currentSong: Song?
var queueIcon: NSImage? = nil
@ -38,6 +39,8 @@ class QueueDataSource: NSObject, NSOutlineViewDataSource {
if newSongRowPos >= 0 {
queue[newSongRowPos].isPlaying = true
}
currentSong = queue[newSongRowPos].song
}
func setQueueIcon(_ state: MPDClient.MPDStatus.State) {

View File

@ -43,9 +43,9 @@ extension MPDClient {
self.fetchStatus()
if let status = self.status {
self.delegate?.didUpdateState(mpdClient: self, state: status.state)
self.delegate?.didUpdateTime(mpdClient: self, total: status.totalTime, elapsedMs: status.elapsedTimeMs)
self.delegate?.didUpdateQueuePos(mpdClient: self, song: status.song)
self.delegate?.didUpdateTime(mpdClient: self, total: status.totalTime, elapsedMs: status.elapsedTimeMs)
self.delegate?.didUpdateState(mpdClient: self, state: status.state)
}
}
if mpdIdle.contains(.update) {