Bind to both IPv4 and 6

This commit is contained in:
James 2018-08-04 00:54:03 +10:00
parent 7f86ac634a
commit 55239ec4aa
4 changed files with 37 additions and 19 deletions

View File

@ -47,6 +47,11 @@ use nfd::Response;
use rest::WebServer; use rest::WebServer;
use std::net::ToSocketAddrs;
use std::sync::Arc;
use std::sync::RwLock;
// TODO: Fetch this over a HTTP request? // TODO: Fetch this over a HTTP request?
static RAW_CONFIG: &'static str = include_str!("../config.toml"); static RAW_CONFIG: &'static str = include_str!("../config.toml");
@ -73,11 +78,33 @@ fn main() {
InstallerFramework::new(config) InstallerFramework::new(config)
}; };
let server = WebServer::new(framework).unwrap(); let addresses = "localhost:0"
.to_socket_addrs()
.expect("No localhost address found");
let mut servers = Vec::new();
let mut http_address = None;
let framework = Arc::new(RwLock::new(framework));
// Startup HTTP server for handling the web view // Startup HTTP server for handling the web view
let http_address = format!("http://{}", server.get_addr()); for address in addresses {
println!("Server: {:?}", http_address); let server = WebServer::with_addr(framework.clone(), address).unwrap();
let addr = server.get_addr();
println!("Server: {:?}", addr);
http_address = Some(addr);
servers.push(server);
}
let http_address = match http_address {
Some(v) => v,
None => panic!("No HTTP address found"),
};
let http_address = format!("http://localhost:{}", http_address.port());
// Init the web view // Init the web view
let size = (1024, 500); let size = (1024, 500);

View File

@ -47,25 +47,15 @@ impl WebServer {
self.addr.clone() self.addr.clone()
} }
/// 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),
)
}
/// Creates a new web server with the specified address. /// 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: Arc<RwLock<InstallerFramework>>, addr: SocketAddr) -> Result<Self, HyperError> {
let (sender, receiver) = channel(); let (sender, receiver) = channel();
let handle = thread::spawn(move || { let handle = thread::spawn(move || {
let shared_framework = Arc::new(RwLock::new(framework));
let server = Http::new() let server = Http::new()
.bind(&addr, move || { .bind(&addr, move || {
Ok(WebService { Ok(WebService {
framework: shared_framework.clone(), framework: framework.clone(),
}) })
}) })
.unwrap(); .unwrap();

View File

@ -27,7 +27,7 @@ pub enum TaskParamType {
/// Downloaded contents of a file /// Downloaded contents of a file
FileContents(Version, Vec<u8>), FileContents(Version, Vec<u8>),
/// Tells the runtime to break parsing other dependencies /// Tells the runtime to break parsing other dependencies
Break Break,
} }
/// A Task is a small, async task conforming to a fixed set of inputs/outputs. /// A Task is a small, async task conforming to a fixed set of inputs/outputs.
@ -103,7 +103,7 @@ impl DependencyTree {
// Check to see if we skip matching other dependencies // Check to see if we skip matching other dependencies
let do_break = match &result { let do_break = match &result {
&TaskParamType::Break => true, &TaskParamType::Break => true,
_ => false _ => false,
}; };
inputs.push(result); inputs.push(result);

View File

@ -225,9 +225,10 @@
app.modify_install = false; app.modify_install = false;
}, },
"uninstall": function() { "uninstall": function() {
app.is_installing = true;
app.confirm_uninstall = false; app.confirm_uninstall = false;
this.select_packages = false; app.modify_install = false;
this.is_installing = true; app.select_packages = false;
stream_ajax("/api/uninstall", function(line) { stream_ajax("/api/uninstall", function(line) {
if (line.hasOwnProperty("Status")) { if (line.hasOwnProperty("Status")) {