diff --git a/src/installer.rs b/src/installer.rs index 9f30526..baac945 100644 --- a/src/installer.rs +++ b/src/installer.rs @@ -30,14 +30,16 @@ impl InstallerFramework { Err(_) => home_dir()?, }; - println!("{:?}", base_dir); - let file = base_dir.join(app_name); - println!("{:?}", file); Some(file.to_str()?.to_owned()) } + /// Sends a request for something to be installed. + pub fn install(&self, items : Vec) { + println!("Framework: Installing {:?}", items); + } + /// Creates a new instance of the Installer Framework with a specified Config. pub fn new(config: Config) -> Self { InstallerFramework { config } diff --git a/src/rest.rs b/src/rest.rs index 86c79b2..8c09578 100644 --- a/src/rest.rs +++ b/src/rest.rs @@ -13,7 +13,6 @@ use serde_json; use futures::Stream; use futures::Future; use futures::future; -use futures::future::FutureResult; use hyper::{self, Error as HyperError, Get, Post, StatusCode}; use hyper::header::{ContentLength, ContentType}; @@ -150,11 +149,25 @@ impl Service for WebService { } (&Post, "/api/start-install") => { // We need to bit of pipelining to get this to work - return Box::new(req.body().concat2().map(|b| { + let cloned_element = self.framework.clone(); + + return Box::new(req.body().concat2().map(move |b| { let results = form_urlencoded::parse(b.as_ref()) .into_owned().collect::>(); - println!("{:?}", results); + let mut to_install = Vec::new(); + + // Transform results into just an array of stuff to install + for (key, value) in results.iter() { + if value == "true" { + to_install.push(key.to_owned()); + } + } + + // Startup a thread to do this operation for us + thread::spawn(move || { + cloned_element.install(to_install); + }); let file = serde_json::to_string(&{}).unwrap(); @@ -174,8 +187,6 @@ impl Service for WebService { path += "index.html"; } - println!("Trying {} => {}", req.path(), path); - match assets::file_from_string(&path) { Some((content_type, file)) => { let content_type = ContentType(content_type.parse().unwrap());