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

Reload album data when the library path is changed

This commit is contained in:
Daniel Barber 2019-03-17 12:35:34 -04:00
parent 487e0cc2c2
commit 280ec0cdc4
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8

View File

@ -11,6 +11,8 @@ import Cocoa
class AlbumViewController: NSViewController,
NSCollectionViewDelegate,
NSCollectionViewDelegateFlowLayout {
var preferences = Preferences()
let paddingWidth: CGFloat = 40
let gutterWidth: CGFloat = 20
@ -36,6 +38,8 @@ class AlbumViewController: NSViewController,
)
albumCollectionView.dataSource = dataSource
preferences.addObserver(self, forKeyPath: "mpdLibraryDir")
}
override func viewWillLayout() {
@ -53,6 +57,20 @@ class AlbumViewController: NSViewController,
layout.setScrollPosition()
}
override func observeValue(
forKeyPath keyPath: String?,
of object: Any?,
change: [NSKeyValueChangeKey : Any]?,
context: UnsafeMutableRawPointer?
) {
switch keyPath {
case "mpdLibraryDir":
albumCollectionView.reloadData()
default:
break
}
}
@objc func updateAlbums(_ notification: Notification) {
guard let albums = notification.userInfo?[Notification.albumsKey] as? [MPDClient.Album]
else { return }