From 51a77c76fabe6b0bd16c7b4ce7b9ff1565eb4038 Mon Sep 17 00:00:00 2001 From: 4yn Date: Mon, 7 Feb 2022 12:41:45 +0800 Subject: [PATCH] mimetype and kyeboard --- .../slider_io/brokenithm-www/index-go.html | 2 +- .../src/slider_io/brokenithm-www/index.html | 2 +- src-tauri/src/slider_io/brokenithm.rs | 38 ++++++++++++++----- src-tauri/src/slider_io/keyboard.rs | 6 ++- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src-tauri/src/slider_io/brokenithm-www/index-go.html b/src-tauri/src/slider_io/brokenithm-www/index-go.html index 8a3db37..4c02700 100644 --- a/src-tauri/src/slider_io/brokenithm-www/index-go.html +++ b/src-tauri/src/slider_io/brokenithm-www/index-go.html @@ -115,6 +115,6 @@ - + diff --git a/src-tauri/src/slider_io/brokenithm-www/index.html b/src-tauri/src/slider_io/brokenithm-www/index.html index f0cc9e4..74a5d00 100644 --- a/src-tauri/src/slider_io/brokenithm-www/index.html +++ b/src-tauri/src/slider_io/brokenithm-www/index.html @@ -114,6 +114,6 @@ - + diff --git a/src-tauri/src/slider_io/brokenithm.rs b/src-tauri/src/slider_io/brokenithm.rs index 9547ff7..76197b9 100644 --- a/src-tauri/src/slider_io/brokenithm.rs +++ b/src-tauri/src/slider_io/brokenithm.rs @@ -33,12 +33,15 @@ async fn error_response() -> Result, Infallible> { // static x: &'static [u8] = include_bytes!("./brokenithm-www/favicon.ico"); -static BROKENITHM_FILES: phf::Map<&'static str, &'static [u8]> = phf_map! { - "app.js" => include_bytes!("./brokenithm-www/app.js"), - "config.js" => include_bytes!("./brokenithm-www/config.js"), - "favicon.ico" => include_bytes!("./brokenithm-www/favicon.ico"), - "index-go.html" => include_bytes!("./brokenithm-www/index-go.html"), - "index.html" => include_bytes!("./brokenithm-www/index.html"), +static BROKENITHM_STR_FILES: phf::Map<&'static str, (&'static str, &'static str)> = phf_map! { + "app.js" => (include_str!("./brokenithm-www/app.js"), "text/javascript"), + "config.js" => (include_str!("./brokenithm-www/config.js"), "text/javascript"), + "index-go.html" => (include_str!("./brokenithm-www/index-go.html"), "text/html"), + "index.html" => (include_str!("./brokenithm-www/index.html"), "text/html"), +}; + +static BROKENITHM_BIN_FILES: phf::Map<&'static str, (&'static [u8], &'static str)> = phf_map! { + "favicon.ico" => (include_bytes!("./brokenithm-www/favicon.ico"), "image/x-icon"), }; async fn serve_file(path: &str) -> Result, Infallible> { @@ -48,7 +51,7 @@ async fn serve_file(path: &str) -> Result, Infallible> { // pb.push(path); // pb.clean(); - // // println!("CWD {:?}", std::env::current_dir()); + // println!("CWD {:?}", std::env::current_dir()); // match File::open(&pb).await { // Ok(f) => { @@ -59,9 +62,24 @@ async fn serve_file(path: &str) -> Result, Infallible> { // } // Err(_) => error_response().await, // } - match BROKENITHM_FILES.get(path) { - Some(x) => Ok(Response::new(Body::from(*x))), - None => error_response().await, + + match ( + BROKENITHM_STR_FILES.get(path), + BROKENITHM_BIN_FILES.get(path), + ) { + (Some((data, mime)), _) => Ok( + Response::builder() + .header(header::CONTENT_TYPE, *mime) + .body(Body::from(*data)) + .unwrap(), + ), + (_, Some((data, mime))) => Ok( + Response::builder() + .header(header::CONTENT_TYPE, *mime) + .body(Body::from(*data)) + .unwrap(), + ), + (None, None) => error_response().await, } } diff --git a/src-tauri/src/slider_io/keyboard.rs b/src-tauri/src/slider_io/keyboard.rs index 0c449dd..12c06d8 100644 --- a/src-tauri/src/slider_io/keyboard.rs +++ b/src-tauri/src/slider_io/keyboard.rs @@ -133,17 +133,19 @@ impl KeyboardOutput { continue; } match (*n, *l) { - (false, true) => { + (true, false) => { let inner: &mut KEYBDINPUT = unsafe { self.kb_buf[self.n_kb_buf as usize].u.ki_mut() }; inner.wVk = keycode; inner.dwFlags = 0; self.n_kb_buf += 1; + // println!("{} down", keycode); } - (true, false) => { + (false, true) => { let inner: &mut KEYBDINPUT = unsafe { self.kb_buf[self.n_kb_buf as usize].u.ki_mut() }; inner.wVk = keycode; inner.dwFlags = KEYEVENTF_KEYUP; self.n_kb_buf += 1; + // println!("{} up", keycode); } _ => {} }