]> git.r.bdr.sh - rbdr/lyricli/blob - Sources/source_manager.swift
Merge branch 'release/0.3.0'
[rbdr/lyricli] / Sources / source_manager.swift
1 // Collect and manage the available and enabled source
2 class SourceManager {
3
4 // List of sources enabled for the crurent platform
5 private var availableSources: [String: Source] = [
6 "arguments": ArgumentsSource(),
7 "itunes": ItunesSource(),
8 "spotify": SpotifySource()
9 ]
10
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 {
15 return currentTrack
16 }
17 }
18
19 return nil
20 }
21
22 // Return the list of enabled sources based on the configuration
23 var enabledSources: [Source] {
24
25 // Checks the config and returns an array of sources based on the
26 // enabled and available ones
27
28 var sources = [Source]()
29
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)
34 }
35 }
36 }
37
38 return sources
39 }
40
41 // Given a source name, it will enable it and add it to the enabled sources config
42 func enable(sourceName: String) {
43 }
44
45 // Given a source name, it will remove it from the enabled sources config
46 func disable(sourceName: String) {
47 }
48
49 // Given a source name, it removes any stored configuration and disables it
50 func reset(sourceName: String) {
51 }
52 }