mirror of
https://github.com/danbee/persephone
synced 2025-03-04 08:39:11 +00:00
Touch the user notifications controller
Static lets are lazily initialised.
This commit is contained in:
parent
96bb9679ab
commit
ef9f1e12c1
@ -10,9 +10,9 @@ import Foundation
|
|||||||
import ReSwift
|
import ReSwift
|
||||||
|
|
||||||
struct App {
|
struct App {
|
||||||
|
static let store = Store<AppState>(reducer: appReducer, state: nil)
|
||||||
|
static let trackTimer = TrackTimer()
|
||||||
|
static let mpdClient = MPDClient(withDelegate: NotificationsController())
|
||||||
static let userNotificationsController = UserNotificationsController()
|
static let userNotificationsController = UserNotificationsController()
|
||||||
static let mpdServerController = MPDServerController()
|
static let mpdServerController = MPDServerController()
|
||||||
static let mpdClient = MPDClient(withDelegate: NotificationsController())
|
|
||||||
static let trackTimer = TrackTimer()
|
|
||||||
static let store = Store<AppState>(reducer: appReducer, state: nil)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,7 @@ class AppDelegate: NSObject,
|
|||||||
|
|
||||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||||
App.mpdServerController.connect()
|
App.mpdServerController.connect()
|
||||||
|
_ = App.userNotificationsController
|
||||||
|
|
||||||
mediaKeyTap = MediaKeyTap(delegate: self)
|
mediaKeyTap = MediaKeyTap(delegate: self)
|
||||||
mediaKeyTap?.start()
|
mediaKeyTap?.start()
|
||||||
|
|||||||
@ -9,17 +9,12 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
class NotificationsController: MPDClientDelegate {
|
class NotificationsController: MPDClientDelegate {
|
||||||
let notificationQueue = DispatchQueue.main
|
func didConnect(mpdClient: MPDClient) {}
|
||||||
|
|
||||||
func didConnect(mpdClient: MPDClient) {
|
|
||||||
sendNotification(name: Notification.didConnect)
|
|
||||||
}
|
|
||||||
|
|
||||||
func willDisconnect(mpdClient: MPDClient) {
|
func willDisconnect(mpdClient: MPDClient) {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
App.store.dispatch(UpdateAlbumListAction(albums: []))
|
App.store.dispatch(UpdateAlbumListAction(albums: []))
|
||||||
}
|
}
|
||||||
sendNotification(name: Notification.willDisconnect)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func didUpdateStatus(mpdClient: MPDClient, status: MPDClient.MPDStatus) {
|
func didUpdateStatus(mpdClient: MPDClient, status: MPDClient.MPDStatus) {
|
||||||
@ -57,14 +52,4 @@ class NotificationsController: MPDClientDelegate {
|
|||||||
App.store.dispatch(UpdateAlbumListAction(albums: albums))
|
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
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user