소스 검색

main: Fix cache setup

Paul Lietar 7 년 전
부모
커밋
b8e4febb8e
1개의 변경된 파일5개의 추가작업 그리고 9개의 파일을 삭제
  1. 5 9
      src/main.rs

+ 5 - 9
src/main.rs

@@ -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()
 }
+