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:
parent
a52ba06a08
commit
e441d7b0d6
@ -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) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user