diff --git a/Persephone.xcodeproj/project.pbxproj b/Persephone.xcodeproj/project.pbxproj index b742579..64aab1c 100644 --- a/Persephone.xcodeproj/project.pbxproj +++ b/Persephone.xcodeproj/project.pbxproj @@ -95,7 +95,6 @@ E4B11BA62274E44A0075461B /* libmpdclient.2.dylib in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = E41B22BF21FB6BBA00D544F6 /* libmpdclient.2.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; E4B11BA72274E4500075461B /* libmpdclient.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = E41B22BF21FB6BBA00D544F6 /* libmpdclient.2.dylib */; }; E4B11BA92274EDE30075461B /* Loading.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4B11BA82274EDE30075461B /* Loading.swift */; }; - E4B11BB02274F71A0075461B /* EnumEquatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4B11BAF2274F71A0075461B /* EnumEquatable.swift */; }; E4B11BB62275374B0075461B /* UserNotificationsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4B11BB52275374B0075461B /* UserNotificationsController.swift */; }; E4B11BB8227538FA0075461B /* CurrentCoverArtView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4B11BB7227538FA0075461B /* CurrentCoverArtView.swift */; }; E4B11BBE2275EDAA0075461B /* PlayerActions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4B11BBD2275EDAA0075461B /* PlayerActions.swift */; }; @@ -105,7 +104,6 @@ E4C8B53E22349002009A20F3 /* MPDIdle.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4C8B53D22349002009A20F3 /* MPDIdle.swift */; }; E4E8CC902204EC7F0024217A /* Delegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E8CC8F2204EC7F0024217A /* Delegate.swift */; }; E4E8CC922204F4B80024217A /* QueueViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E8CC912204F4B80024217A /* QueueViewController.swift */; }; - E4E8CC942206097F0024217A /* NotificationsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E8CC932206097F0024217A /* NotificationsController.swift */; }; E4E8CC9A22075D370024217A /* MPDSong.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E8CC9922075D370024217A /* MPDSong.swift */; }; E4EB2379220F10B8008C70C0 /* MPDPair.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4EB2378220F10B8008C70C0 /* MPDPair.swift */; }; E4EB237B220F7CF1008C70C0 /* MPDAlbum.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4EB237A220F7CF1008C70C0 /* MPDAlbum.swift */; }; @@ -291,7 +289,6 @@ E4B11B7C2274E36D0075461B /* Differ.framework.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; name = Differ.framework.dSYM; path = Carthage/Build/Mac/Differ.framework.dSYM; sourceTree = ""; }; E4B11B7D2274E36D0075461B /* Differ.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Differ.framework; path = Carthage/Build/Mac/Differ.framework; sourceTree = ""; }; E4B11BA82274EDE30075461B /* Loading.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Loading.swift; sourceTree = ""; }; - E4B11BAF2274F71A0075461B /* EnumEquatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnumEquatable.swift; sourceTree = ""; }; E4B11BB52275374B0075461B /* UserNotificationsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserNotificationsController.swift; sourceTree = ""; }; E4B11BB7227538FA0075461B /* CurrentCoverArtView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentCoverArtView.swift; sourceTree = ""; }; E4B11BBD2275EDAA0075461B /* PlayerActions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerActions.swift; sourceTree = ""; }; @@ -301,7 +298,6 @@ E4C8B53D22349002009A20F3 /* MPDIdle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPDIdle.swift; sourceTree = ""; }; E4E8CC8F2204EC7F0024217A /* Delegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Delegate.swift; sourceTree = ""; }; E4E8CC912204F4B80024217A /* QueueViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueueViewController.swift; sourceTree = ""; }; - E4E8CC932206097F0024217A /* NotificationsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationsController.swift; sourceTree = ""; }; E4E8CC9922075D370024217A /* MPDSong.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPDSong.swift; sourceTree = ""; }; E4EB2378220F10B8008C70C0 /* MPDPair.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPDPair.swift; sourceTree = ""; }; E4EB237A220F7CF1008C70C0 /* MPDAlbum.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPDAlbum.swift; sourceTree = ""; }; @@ -376,7 +372,6 @@ E407861A2110CE6E006887B1 /* Persephone */ = { isa = PBXGroup; children = ( - E4B11BAE2274F7030075461B /* Protocols */, E407861B2110CE6E006887B1 /* AppDelegate.swift */, E44051932278765A0090CD6F /* App.swift */, E407861F2110CE70006887B1 /* Assets.xcassets */, @@ -639,14 +634,6 @@ path = Actions; sourceTree = ""; }; - E4B11BAE2274F7030075461B /* Protocols */ = { - isa = PBXGroup; - children = ( - E4B11BAF2274F71A0075461B /* EnumEquatable.swift */, - ); - path = Protocols; - sourceTree = ""; - }; E4D1B594220BA2490026F233 /* Models */ = { isa = PBXGroup; children = ( @@ -674,7 +661,6 @@ E408D3C1220E134F0006D9BE /* AlbumViewController.swift */, E47E2FD4222071FD00F747E6 /* AlbumViewItem.swift */, E47E2FD022205C4600F747E6 /* MainSplitViewController.swift */, - E4E8CC932206097F0024217A /* NotificationsController.swift */, E4E8CC912204F4B80024217A /* QueueViewController.swift */, E465049921E94DF500A70F4C /* WindowController.swift */, E4B11BB52275374B0075461B /* UserNotificationsController.swift */, @@ -918,7 +904,6 @@ E450AD9522262DF10091BED3 /* CoverArtQueue.swift in Sources */, E41E52FD223BF87300173814 /* MPDClient+Connection.swift in Sources */, E450AD7E222620A10091BED3 /* Album.swift in Sources */, - E4E8CC942206097F0024217A /* NotificationsController.swift in Sources */, E408D3B6220DD8970006D9BE /* Notification.swift in Sources */, E45962C62241A78500FC1A1E /* MPDCommand.swift in Sources */, E408D3B9220DE98F0006D9BE /* NSUserInterfaceItemIdentifier.swift in Sources */, @@ -938,7 +923,6 @@ E407861C2110CE6E006887B1 /* AppDelegate.swift in Sources */, E4B11B75226CC4D30075461B /* QueueReducer.swift in Sources */, E41E5309223C020400173814 /* MPDClient+Command.swift in Sources */, - E4B11BB02274F71A0075461B /* EnumEquatable.swift in Sources */, E4B11B73226A6C770075461B /* TrackTimer.swift in Sources */, E44051942278765A0090CD6F /* App.swift in Sources */, E4B11B79226D346B0075461B /* AlbumListReducer.swift in Sources */, diff --git a/Persephone/App.swift b/Persephone/App.swift index 14835a1..39e8615 100644 --- a/Persephone/App.swift +++ b/Persephone/App.swift @@ -12,7 +12,7 @@ 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: mpdServerController) } diff --git a/Persephone/Controllers/MPDServerController.swift b/Persephone/Controllers/MPDServerController.swift index 3f749ef..414a263 100644 --- a/Persephone/Controllers/MPDServerController.swift +++ b/Persephone/Controllers/MPDServerController.swift @@ -17,11 +17,15 @@ class MPDServerController { } func connect() { - App.store.dispatch(MPDConnectAction()) + DispatchQueue.main.async { + App.store.dispatch(MPDConnectAction()) + } } func disconnect() { - App.store.dispatch(MPDDisconnectAction()) + DispatchQueue.main.async { + App.store.dispatch(MPDDisconnectAction()) + } } } @@ -33,3 +37,49 @@ extension MPDServerController: StoreSubscriber { connect() } } + +extension MPDServerController: MPDClientDelegate { + func didConnect(mpdClient: MPDClient) {} + + func willDisconnect(mpdClient: MPDClient) { + DispatchQueue.main.async { + App.store.dispatch(UpdateAlbumListAction(albums: [])) + } + } + + func didUpdateStatus(mpdClient: MPDClient, status: MPDClient.MPDStatus) { + DispatchQueue.main.async { + App.store.dispatch(UpdateStatusAction(status: status)) + } + } + + func willStartDatabaseUpdate(mpdClient: MPDClient) { + DispatchQueue.main.async { + App.store.dispatch(StartedDatabaseUpdateAction()) + } + } + + func didFinishDatabaseUpdate(mpdClient: MPDClient) { + DispatchQueue.main.async { + App.store.dispatch(FinishedDatabaseUpdateAction()) + } + } + + func didUpdateQueue(mpdClient: MPDClient, queue: [MPDClient.MPDSong]) { + DispatchQueue.main.async { + App.store.dispatch(UpdateQueueAction(queue: queue)) + } + } + + func didUpdateQueuePos(mpdClient: MPDClient, song: Int) { + DispatchQueue.main.async { + App.store.dispatch(UpdateQueuePosAction(queuePos: song)) + } + } + + func didLoadAlbums(mpdClient: MPDClient, albums: [MPDClient.MPDAlbum]) { + DispatchQueue.main.async { + App.store.dispatch(UpdateAlbumListAction(albums: albums)) + } + } +} diff --git a/Persephone/Controllers/NotificationsController.swift b/Persephone/Controllers/NotificationsController.swift deleted file mode 100644 index e2e81af..0000000 --- a/Persephone/Controllers/NotificationsController.swift +++ /dev/null @@ -1,55 +0,0 @@ -// -// NotificationsController.swift -// Persephone -// -// Created by Daniel Barber on 2019/2/02. -// Copyright © 2019 Dan Barber. All rights reserved. -// - -import Foundation - -class NotificationsController: MPDClientDelegate { - func didConnect(mpdClient: MPDClient) {} - - func willDisconnect(mpdClient: MPDClient) { - DispatchQueue.main.async { - App.store.dispatch(UpdateAlbumListAction(albums: [])) - } - } - - func didUpdateStatus(mpdClient: MPDClient, status: MPDClient.MPDStatus) { - DispatchQueue.main.async { - App.store.dispatch(UpdateStatusAction(status: status)) - } - } - - func willStartDatabaseUpdate(mpdClient: MPDClient) { - DispatchQueue.main.async { - App.store.dispatch(StartedDatabaseUpdateAction()) - } - } - - func didFinishDatabaseUpdate(mpdClient: MPDClient) { - DispatchQueue.main.async { - App.store.dispatch(FinishedDatabaseUpdateAction()) - } - } - - func didUpdateQueue(mpdClient: MPDClient, queue: [MPDClient.MPDSong]) { - DispatchQueue.main.async { - App.store.dispatch(UpdateQueueAction(queue: queue)) - } - } - - func didUpdateQueuePos(mpdClient: MPDClient, song: Int) { - DispatchQueue.main.async { - App.store.dispatch(UpdateQueuePosAction(queuePos: song)) - } - } - - func didLoadAlbums(mpdClient: MPDClient, albums: [MPDClient.MPDAlbum]) { - DispatchQueue.main.async { - App.store.dispatch(UpdateAlbumListAction(albums: albums)) - } - } -} diff --git a/Persephone/MPDClient/Models/MPDAlbum.swift b/Persephone/MPDClient/Models/MPDAlbum.swift index 2b87039..9b9bb94 100644 --- a/Persephone/MPDClient/Models/MPDAlbum.swift +++ b/Persephone/MPDClient/Models/MPDAlbum.swift @@ -9,7 +9,7 @@ import Foundation extension MPDClient { - struct MPDAlbum { + struct MPDAlbum: Equatable { let title: String let artist: String } diff --git a/Persephone/Models/Album.swift b/Persephone/Models/Album.swift index 34ef975..df91dc7 100644 --- a/Persephone/Models/Album.swift +++ b/Persephone/Models/Album.swift @@ -32,8 +32,7 @@ struct Album { extension Album: Equatable { static func == (lhs: Album, rhs: Album) -> Bool { - return (lhs.artist == rhs.artist) && - (lhs.title == rhs.title) && + return (lhs.mpdAlbum == rhs.mpdAlbum) && (lhs.coverArt ~= rhs.coverArt) } } diff --git a/Persephone/Models/Loading.swift b/Persephone/Models/Loading.swift index c81c164..eeb244a 100644 --- a/Persephone/Models/Loading.swift +++ b/Persephone/Models/Loading.swift @@ -13,9 +13,7 @@ enum Loading { case loading case loaded(T) case error(Error) -} -extension Loading: EnumEquatable { static func ~= (lhs: Loading, rhs: Loading) -> Bool { switch (lhs, rhs) { case (_, .notLoaded), diff --git a/Persephone/Models/QueueItem.swift b/Persephone/Models/QueueItem.swift index 9ffdf63..c087674 100644 --- a/Persephone/Models/QueueItem.swift +++ b/Persephone/Models/QueueItem.swift @@ -8,16 +8,8 @@ import Foundation -struct QueueItem { +struct QueueItem: Equatable { var song: Song var queuePos: Int var isPlaying: Bool } - -extension QueueItem: Equatable { - static func == (lhs: QueueItem, rhs: QueueItem) -> Bool { - return (lhs.song == rhs.song) && - (lhs.queuePos == rhs.queuePos) && - (lhs.isPlaying == rhs.isPlaying) - } -} diff --git a/Persephone/Protocols/EnumEquatable.swift b/Persephone/Protocols/EnumEquatable.swift deleted file mode 100644 index 1295f8f..0000000 --- a/Persephone/Protocols/EnumEquatable.swift +++ /dev/null @@ -1,11 +0,0 @@ -// -// EnumEquatable.swift -// Persephone -// -// Created by Daniel Barber on 2019/4/27. -// Copyright © 2019 Dan Barber. All rights reserved. -// - -protocol EnumEquatable { - static func ~=(lhs: Self, rhs: Self) -> Bool -} diff --git a/Persephone/State/AlbumListState.swift b/Persephone/State/AlbumListState.swift index bf00dac..a7d763c 100644 --- a/Persephone/State/AlbumListState.swift +++ b/Persephone/State/AlbumListState.swift @@ -8,12 +8,6 @@ import ReSwift -struct AlbumListState: StateType { +struct AlbumListState: StateType, Equatable { var albums: [Album] = [] } - -extension AlbumListState: Equatable { - static func == (lhs: AlbumListState, rhs: AlbumListState) -> Bool { - return lhs.albums == rhs.albums - } -} diff --git a/Persephone/State/PreferencesState.swift b/Persephone/State/PreferencesState.swift index b11db5d..66e5bb8 100644 --- a/Persephone/State/PreferencesState.swift +++ b/Persephone/State/PreferencesState.swift @@ -9,7 +9,7 @@ import Foundation import ReSwift -struct PreferencesState: StateType { +struct PreferencesState: StateType, Equatable { let preferences = UserDefaults.standard var mpdServer: MPDServer diff --git a/Persephone/State/QueueState.swift b/Persephone/State/QueueState.swift index d9b32a3..cfb040b 100644 --- a/Persephone/State/QueueState.swift +++ b/Persephone/State/QueueState.swift @@ -8,17 +8,9 @@ import ReSwift -struct QueueState: StateType { +struct QueueState: StateType, Equatable { var queue: [QueueItem] = [] var queuePos: Int = -1 var state: MPDClient.MPDStatus.State? } - -extension QueueState: Equatable { - static func == (lhs: QueueState, rhs: QueueState) -> Bool { - return (lhs.queue == rhs.queue) && - (lhs.queuePos == rhs.queuePos) && - (lhs.state == rhs.state) - } -}