main: Fix cache setup

This commit is contained in:
Paul Lietar 2017-02-22 14:28:09 +00:00
parent 541114e2b4
commit b8e4febb8e

View file

@ -185,18 +185,19 @@ struct Main {
impl Main {
fn new(handle: Handle,
config: Config,
cache: Option<Cache>,
backend: fn(Option<String>) -> Box<Sink>,
device: Option<String>,
mixer: fn() -> Box<Mixer>) -> Main
{
Main {
handle: handle.clone(),
cache: cache,
config: config,
backend: backend,
device: device,
mixer: mixer,
cache: None,
connect: Box::new(futures::future::empty()),
discovery: None,
spirc: None,
@ -215,6 +216,7 @@ impl Main {
fn credentials(&mut self, credentials: Credentials) {
let config = self.config.clone();
let handle = self.handle.clone();
let connection = Session::connect(config, credentials, self.cache.clone(), handle);
self.connect = connection;
@ -224,10 +226,6 @@ impl Main {
self.handle.spawn(task);
}
}
fn cache(&mut self, cache: Cache) {
self.cache = Some(cache);
}
}
impl Future for Main {
@ -302,16 +300,14 @@ fn main() {
let args: Vec<String> = std::env::args().collect();
let Setup { backend, config, device, cache, enable_discovery, credentials, mixer } = setup(&args);
let mut task = Main::new(handle, config.clone(), backend, device, mixer);
let mut task = Main::new(handle, config.clone(), cache, backend, device, mixer);
if enable_discovery {
task.discovery();
}
if let Some(credentials) = credentials {
task.credentials(credentials);
}
if let Some(cache) = cache {
task.cache(cache);
}
core.run(task).unwrap()
}