diff options
-rw-r--r-- | src/gui.rs | 13 | ||||
-rw-r--r-- | src/server.rs | 14 |
2 files changed, 22 insertions, 5 deletions
@@ -1,5 +1,9 @@ +use std::fmt::Debug; + use anyhow::Error; use anyhow::Result; +use web_view::WVResult; +use web_view::WebView; use crate::app::App; use crate::cli::*; @@ -27,7 +31,7 @@ pub fn run_gui(config: Configuration, adr: String) -> Result<()> { } }; - let webview_content = web_view::Content::Url(adr.clone()); + let webview_content = web_view::Content::Url(format!("http://{}", adr)); web_view::builder() .title("My Project") @@ -35,10 +39,15 @@ pub fn run_gui(config: Configuration, adr: String) -> Result<()> { .resizable(true) .debug(true) .user_data(()) - .invoke_handler(|_webview, _arg| Ok(())) + .invoke_handler(invoke_handler) .build() .map_err(Error::from)? .run() .map_err(Error::from) } +fn invoke_handler<T: Debug>(webview: &mut WebView<T>, s: &str) -> WVResult { + debug!("invoke-handler: {:?}, {:?}", webview, s); + Ok(()) +} + diff --git a/src/server.rs b/src/server.rs index 65956e8..bf97b87 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use actix_web::{web, HttpResponse, Responder}; use anyhow::Error; use anyhow::Result; @@ -15,7 +17,7 @@ pub fn do_start(cli: &CLI) -> bool { } pub fn is_running(server_lock: &Pidlock) -> bool { - *server_lock.state() == PidlockState::Acquired + PathBuf::from("/tmp/distrox_server.pid").exists() } @@ -26,7 +28,7 @@ pub async fn run_server(mut server_lock: Pidlock, adr: String) -> Result<()> { info!("Got PID lock for server"); actix_web::HttpServer::new(|| { actix_web::App::new() - .service(actix_web::web::resource("/{name}/{id}/index.html").to(index)) + .route("*", actix_web::web::get().to(index)) }) .bind(adr.clone()) .expect(&format!("Could not bind to address {}", adr)) @@ -39,6 +41,12 @@ pub async fn run_server(mut server_lock: Pidlock, adr: String) -> Result<()> { } async fn index() -> impl Responder { - HttpResponse::Ok() + debug!("serve index"); + format!("{pre}{style}{index}{post}", + pre = include_str!("../assets/index_pre.html"), + style = include_str!("../assets/style.css"), + index = include_str!("../assets/index.html"), + post = include_str!("../assets/index_post.html"), + ) } |