mirror of
https://github.com/yuzu-emu/liftinstall.git
synced 2024-11-22 15:35:38 +01:00
Clean up code using Rustfmt
This commit is contained in:
parent
cf41f552c4
commit
4ed50c885b
@ -18,8 +18,8 @@ pub fn file_from_string(file_path : &str) -> Option<(ContentType, Cow<'static, [
|
||||
let ext = &file_path[ext_ptr + 1..];
|
||||
|
||||
get_mime_type(ext)
|
||||
},
|
||||
None => octet_stream()
|
||||
}
|
||||
None => octet_stream(),
|
||||
};
|
||||
|
||||
let string_mime = guessed_mime.to_string();
|
||||
@ -30,6 +30,6 @@ pub fn file_from_string(file_path : &str) -> Option<(ContentType, Cow<'static, [
|
||||
match FILES.get(&format!("static{}", file_path)) {
|
||||
Ok(val) => Some((content_type, val)),
|
||||
// Only error is a not found one
|
||||
Err(_) => None
|
||||
Err(_) => None,
|
||||
}
|
||||
}
|
||||
|
@ -12,20 +12,20 @@ use serde_json::{self, Error as SerdeError};
|
||||
pub struct PackageDescription {
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub default : Option<bool>
|
||||
pub default: Option<bool>,
|
||||
}
|
||||
|
||||
/// Describes the application itself.
|
||||
#[derive(Deserialize, Serialize, Clone)]
|
||||
pub struct GeneralConfig {
|
||||
pub name: String,
|
||||
pub installing_message : String
|
||||
pub installing_message: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Clone)]
|
||||
pub struct Config {
|
||||
pub general: GeneralConfig,
|
||||
pub packages : Vec<PackageDescription>
|
||||
pub packages: Vec<PackageDescription>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
@ -12,7 +12,7 @@ use config::Config;
|
||||
/// The installer framework contains metadata about packages, what is installable, what isn't,
|
||||
/// etc.
|
||||
pub struct InstallerFramework {
|
||||
config : Config
|
||||
config: Config,
|
||||
}
|
||||
|
||||
impl InstallerFramework {
|
||||
@ -27,7 +27,7 @@ impl InstallerFramework {
|
||||
|
||||
let base_dir = match var("LOCALAPPDATA") {
|
||||
Ok(path) => PathBuf::from(path),
|
||||
Err(_) => home_dir()?
|
||||
Err(_) => home_dir()?,
|
||||
};
|
||||
|
||||
println!("{:?}", base_dir);
|
||||
@ -40,8 +40,6 @@ impl InstallerFramework {
|
||||
|
||||
/// Creates a new instance of the Installer Framework with a specified Config.
|
||||
pub fn new(config: Config) -> Self {
|
||||
InstallerFramework {
|
||||
config
|
||||
}
|
||||
InstallerFramework { config }
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
extern crate web_view;
|
||||
|
||||
extern crate futures;
|
||||
extern crate hyper;
|
||||
extern crate hyper_tls;
|
||||
extern crate tokio_core;
|
||||
extern crate futures;
|
||||
extern crate mime_guess;
|
||||
extern crate tokio_core;
|
||||
|
||||
extern crate includedir;
|
||||
extern crate phf;
|
||||
@ -63,6 +63,6 @@ fn main() {
|
||||
debug,
|
||||
init_cb,
|
||||
/* frontend_cb: */ |_, _, _| {},
|
||||
userdata
|
||||
userdata,
|
||||
);
|
||||
}
|
||||
|
68
src/rest.rs
68
src/rest.rs
@ -12,11 +12,11 @@ use futures::future;
|
||||
use futures::future::FutureResult;
|
||||
|
||||
use hyper;
|
||||
use hyper::{Get, StatusCode, Error as HyperError};
|
||||
use hyper::{Error as HyperError, Get, StatusCode};
|
||||
use hyper::header::{ContentLength, ContentType};
|
||||
use hyper::server::{Http, Service, Request, Response};
|
||||
use hyper::server::{Http, Request, Response, Service};
|
||||
|
||||
use std::net::{SocketAddr, IpAddr, Ipv4Addr};
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use std::thread::{self, JoinHandle};
|
||||
use std::process::exit;
|
||||
use std::sync::Arc;
|
||||
@ -28,13 +28,13 @@ use installer::InstallerFramework;
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct FileSelection {
|
||||
path : Option<String>
|
||||
path: Option<String>,
|
||||
}
|
||||
|
||||
/// Encapsulates Hyper's state.
|
||||
pub struct WebServer {
|
||||
handle : JoinHandle<()>,
|
||||
addr : SocketAddr
|
||||
_handle: JoinHandle<()>,
|
||||
addr: SocketAddr,
|
||||
}
|
||||
|
||||
impl WebServer {
|
||||
@ -45,24 +45,26 @@ impl WebServer {
|
||||
|
||||
/// Creates a new web server, bound to a random port on localhost.
|
||||
pub fn new(framework: InstallerFramework) -> Result<Self, HyperError> {
|
||||
WebServer::with_addr(framework, SocketAddr::new(
|
||||
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 0))
|
||||
WebServer::with_addr(
|
||||
framework,
|
||||
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 0),
|
||||
)
|
||||
}
|
||||
|
||||
/// Creates a new web server with the specified address.
|
||||
pub fn with_addr(framework : InstallerFramework, addr : SocketAddr)
|
||||
-> Result<Self, HyperError> {
|
||||
pub fn with_addr(framework: InstallerFramework, addr: SocketAddr) -> Result<Self, HyperError> {
|
||||
let (sender, receiver) = channel();
|
||||
|
||||
let handle = thread::spawn(move || {
|
||||
let shared_framework = Arc::new(framework);
|
||||
|
||||
let server =
|
||||
Http::new().bind(&addr, move ||
|
||||
let server = Http::new()
|
||||
.bind(&addr, move || {
|
||||
Ok(WebService {
|
||||
framework : shared_framework.clone()
|
||||
framework: shared_framework.clone(),
|
||||
})
|
||||
).unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
sender.send(server.local_addr().unwrap()).unwrap();
|
||||
|
||||
@ -72,13 +74,14 @@ impl WebServer {
|
||||
let addr = receiver.recv().unwrap();
|
||||
|
||||
Ok(WebServer {
|
||||
handle, addr
|
||||
_handle: handle,
|
||||
addr,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct WebService {
|
||||
framework : Arc<InstallerFramework>
|
||||
framework: Arc<InstallerFramework>,
|
||||
}
|
||||
|
||||
impl Service for WebService {
|
||||
@ -92,24 +95,24 @@ impl Service for WebService {
|
||||
// This endpoint should be usable directly from a <script> tag during loading.
|
||||
// TODO: Handle errors
|
||||
(&Get, "/api/config") => {
|
||||
let file = enscapsulate_json("config",
|
||||
&self.framework.get_config().to_json_str().unwrap());
|
||||
let file = enscapsulate_json(
|
||||
"config",
|
||||
&self.framework.get_config().to_json_str().unwrap(),
|
||||
);
|
||||
|
||||
Response::<hyper::Body>::new()
|
||||
.with_header(ContentLength(file.len() as u64))
|
||||
.with_header(ContentType::json())
|
||||
.with_body(file)
|
||||
},
|
||||
}
|
||||
(&Get, "/api/file-select") => {
|
||||
let file_dialog = nfd::open_pick_folder(None).unwrap();
|
||||
let file = match file_dialog {
|
||||
NfdResponse::Okay(path) => Some(path),
|
||||
_ => None
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let response = FileSelection {
|
||||
path : file
|
||||
};
|
||||
let response = FileSelection { path: file };
|
||||
|
||||
let file = serde_json::to_string(&response).unwrap();
|
||||
|
||||
@ -117,13 +120,11 @@ impl Service for WebService {
|
||||
.with_header(ContentLength(file.len() as u64))
|
||||
.with_header(ContentType::json())
|
||||
.with_body(file)
|
||||
},
|
||||
}
|
||||
(&Get, "/api/default-path") => {
|
||||
let path = self.framework.get_default_path();
|
||||
|
||||
let response = FileSelection {
|
||||
path
|
||||
};
|
||||
let response = FileSelection { path };
|
||||
|
||||
let file = serde_json::to_string(&response).unwrap();
|
||||
|
||||
@ -131,10 +132,10 @@ impl Service for WebService {
|
||||
.with_header(ContentLength(file.len() as u64))
|
||||
.with_header(ContentType::json())
|
||||
.with_body(file)
|
||||
},
|
||||
}
|
||||
(&Get, "/api/exit") => {
|
||||
exit(0);
|
||||
},
|
||||
}
|
||||
|
||||
// Static file handler
|
||||
(&Get, _) => {
|
||||
@ -152,14 +153,11 @@ impl Service for WebService {
|
||||
.with_header(ContentLength(file.len() as u64))
|
||||
.with_header(content_type)
|
||||
.with_body(file),
|
||||
None => Response::new()
|
||||
.with_status(StatusCode::NotFound)
|
||||
None => Response::new().with_status(StatusCode::NotFound),
|
||||
}
|
||||
}
|
||||
},
|
||||
// Fallthrough for POST/PUT/CONNECT/...
|
||||
_ => {
|
||||
Response::new().with_status(StatusCode::NotFound)
|
||||
}
|
||||
_ => Response::new().with_status(StatusCode::NotFound),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user