1 // Collect and manage the available and enabled source
4 // List of sources enabled for the crurent platform
5 private var availableSources: [String: Source] = [
6 "arguments": ArgumentsSource(),
7 "itunes": ItunesSource(),
8 "spotify": SpotifySource()
11 // Iterate over the sources until we find a track or run out of sources
12 var currentTrack: Track? {
13 for source in enabledSources {
14 if let currentTrack = source.currentTrack {
22 // Return the list of enabled sources based on the configuration
23 var enabledSources: [Source] {
25 // Checks the config and returns an array of sources based on the
26 // enabled and available ones
28 var sources = [Source]()
30 if let sourceNames = Configuration.shared["enabled_sources"] as? [String] {
31 for sourceName in sourceNames {
32 if let source = availableSources[sourceName] {
33 sources.append(source)
41 // Given a source name, it will enable it and add it to the enabled sources config
42 func enable(sourceName: String) {
45 // Given a source name, it will remove it from the enabled sources config
46 func disable(sourceName: String) {
49 // Given a source name, it removes any stored configuration and disables it
50 func reset(sourceName: String) {