From 280ec0cdc40b616a3a04e96ca3f5370d44238794 Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Sun, 17 Mar 2019 12:35:34 -0400 Subject: [PATCH] Reload album data when the library path is changed --- .../Controllers/AlbumViewController.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Persephone/Controllers/AlbumViewController.swift b/Persephone/Controllers/AlbumViewController.swift index 144a455..4689233 100644 --- a/Persephone/Controllers/AlbumViewController.swift +++ b/Persephone/Controllers/AlbumViewController.swift @@ -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 }