summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-05-12 21:42:02 +0200
committerMatthias Beyer <mail@beyermatthias.de>2020-05-12 22:14:03 +0200
commitccef8f81f3905f5545db97b9bd720570e3381289 (patch)
tree9528c4af85a175a49c95141d400a3dcd42d58a4f
parent87789ae9f22d9469e7b1e451bc00485ae9b5f2e3 (diff)
Switch to multi-threaded architecture
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--Cargo.toml2
-rw-r--r--src/main.rs40
2 files changed, 28 insertions, 14 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 8149941..7e3e944 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -41,4 +41,4 @@ web-view = "0.6"
handlebars = "3"
actix-rt = "1"
actix-web = "2"
-
+port_check = "0.1"
diff --git a/src/main.rs b/src/main.rs
index 043680b..0eeb683 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -46,9 +46,9 @@ use futures::future::FutureExt;
use futures::future::TryFutureExt;
use serde_json::to_string_pretty as serde_json_to_string_pretty;
use serde_json::from_str as serde_json_from_str;
-use failure::Fallible as Result;
-use failure::Error;
-use failure::err_msg;
+use anyhow::Result;
+use anyhow::Error;
+use actix_web::{web, HttpResponse, Responder};
use crate::app::App;
use crate::cli::cli;
@@ -65,10 +65,10 @@ use crate::types::util::Version;
use std::process::exit;
-#[actix_rt::main]
-async fn main() -> Result<()> {
+fn main() -> Result<()> {
let cli = cli()?;
let _ = env_logger::init();
+ let port = port_check::free_local_port().expect("Could not find free port");
debug!("Logger initialized");
let config_file_name = PathBuf::from("distrox.toml");
@@ -100,20 +100,34 @@ async fn main() -> Result<()> {
}
};
- let html_content = include_str!("../assets/index.html");
-
- let mut view = web_view::builder()
+ let adr = format!("127.0.0.1:{}", port);
+ let webview_content = web_view::Content::Url(adr.clone());
+
+ actix_rt::spawn(async move {
+ actix_web::HttpServer::new(|| {
+ actix_web::App::new()
+ .service(actix_web::web::resource("/{name}/{id}/index.html").to(index))
+ })
+ .bind(adr.clone())
+ .expect(&format!("Could not bind to address {}", adr))
+ .run()
+ .await;
+ });
+
+ web_view::builder()
.title("My Project")
- .content(web_view::Content::Html(html_content))
+ .content(webview_content)
.resizable(true)
.debug(true)
.user_data(())
.invoke_handler(|_webview, _arg| Ok(()))
.build()
- .map_err(Error::from)?;
-
- view.inject_css(include_str!("../assets/style.css"))?;
+ .map_err(Error::from)?
+ .run()
+ .map_err(Error::from)
+}
- view.run().map_err(Error::from)
+async fn index() -> impl Responder {
+ HttpResponse::Ok()
}