diff --git a/Persephone/App.swift b/Persephone/App.swift index 0383eb7..14835a1 100644 --- a/Persephone/App.swift +++ b/Persephone/App.swift @@ -10,9 +10,9 @@ import Foundation import ReSwift struct App { + static let store = Store(reducer: appReducer, state: nil) + static let trackTimer = TrackTimer() + static let mpdClient = MPDClient(withDelegate: NotificationsController()) static let userNotificationsController = UserNotificationsController() static let mpdServerController = MPDServerController() - static let mpdClient = MPDClient(withDelegate: NotificationsController()) - static let trackTimer = TrackTimer() - static let store = Store(reducer: appReducer, state: nil) } diff --git a/Persephone/AppDelegate.swift b/Persephone/AppDelegate.swift index 337e923..967c315 100644 --- a/Persephone/AppDelegate.swift +++ b/Persephone/AppDelegate.swift @@ -18,6 +18,7 @@ class AppDelegate: NSObject, func applicationDidFinishLaunching(_ aNotification: Notification) { App.mpdServerController.connect() + _ = App.userNotificationsController mediaKeyTap = MediaKeyTap(delegate: self) mediaKeyTap?.start() diff --git a/Persephone/Controllers/NotificationsController.swift b/Persephone/Controllers/NotificationsController.swift index ce5a8fe..e2e81af 100644 --- a/Persephone/Controllers/NotificationsController.swift +++ b/Persephone/Controllers/NotificationsController.swift @@ -9,17 +9,12 @@ import Foundation class NotificationsController: MPDClientDelegate { - let notificationQueue = DispatchQueue.main - - func didConnect(mpdClient: MPDClient) { - sendNotification(name: Notification.didConnect) - } + func didConnect(mpdClient: MPDClient) {} func willDisconnect(mpdClient: MPDClient) { DispatchQueue.main.async { App.store.dispatch(UpdateAlbumListAction(albums: [])) } - sendNotification(name: Notification.willDisconnect) } func didUpdateStatus(mpdClient: MPDClient, status: MPDClient.MPDStatus) { @@ -57,14 +52,4 @@ class NotificationsController: MPDClientDelegate { App.store.dispatch(UpdateAlbumListAction(albums: albums)) } } - - private func sendNotification(name: Notification.Name, userInfo: [AnyHashable : Any] = [:]) { - self.notificationQueue.async { - NotificationCenter.default.post( - name: name, - object: App.mpdClient, - userInfo: userInfo - ) - } - } }