]> git.r.bdr.sh - rbdr/lyricli/blame - Sources/source_manager.swift
Update the Version
[rbdr/lyricli] / Sources / source_manager.swift
CommitLineData
d852b84e 1// Collect and manage the available and enabled source
a968bff7 2class SourceManager {
4425e900 3
d852b84e 4 // List of sources enabled for the crurent platform
4425e900 5 private var availableSources: [String: Source] = [
f24ce9a2
BB
6 "arguments": ArgumentsSource(),
7 "itunes": ItunesSource()
4425e900
BB
8 ]
9
d852b84e 10 // Iterate over the sources until we find a track or run out of sources
4425e900 11 var currentTrack: Track? {
1263f62c
BB
12 for source in enabledSources {
13 if let currentTrack = source.currentTrack {
14 return currentTrack
4425e900 15 }
4425e900 16 }
1263f62c
BB
17
18 return nil
4425e900
BB
19 }
20
d852b84e 21 // Return the list of enabled sources based on the configuration
4425e900
BB
22 var enabledSources: [Source] {
23
24 // Checks the config and returns an array of sources based on the
25 // enabled and available ones
26
1263f62c 27 var sources = [Source]()
4425e900 28
d852b84e 29 if let sourceNames = Configuration.shared["enabled_sources"] as? [String] {
1263f62c
BB
30 for sourceName in sourceNames {
31 if let source = availableSources[sourceName] {
32 sources.append(source)
4425e900
BB
33 }
34 }
4425e900 35 }
1263f62c
BB
36
37 return sources
4425e900
BB
38 }
39
d852b84e 40 // Given a source name, it will enable it and add it to the enabled sources config
4425e900
BB
41 func enable(sourceName: String) {
42 }
43
d852b84e 44 // Given a source name, it will remove it from the enabled sources config
4425e900
BB
45 func disable(sourceName: String) {
46 }
47
d852b84e 48 // Given a source name, it removes any stored configuration and disables it
4425e900
BB
49 func reset(sourceName: String) {
50 }
4425e900 51}