1
0
mirror of https://github.com/4yn/slidershim.git synced 2025-02-02 04:27:58 +01:00

mimetype and kyeboard

This commit is contained in:
4yn 2022-02-07 12:41:45 +08:00
parent 3ba7f2b8f2
commit 51a77c76fa
4 changed files with 34 additions and 14 deletions

View File

@ -115,6 +115,6 @@
</div> </div>
</div> </div>
<script src="/config.js"></script> <script src="/config.js"></script>
<script src="/src.js"></script> <script src="/app.js"></script>
</body> </body>
</html> </html>

View File

@ -114,6 +114,6 @@
</div> </div>
</div> </div>
<script src="/config.js"></script> <script src="/config.js"></script>
<script src="/src.js"></script> <script src="/app.js"></script>
</body> </body>
</html> </html>

View File

@ -33,12 +33,15 @@ async fn error_response() -> Result<Response<Body>, Infallible> {
// static x: &'static [u8] = include_bytes!("./brokenithm-www/favicon.ico"); // static x: &'static [u8] = include_bytes!("./brokenithm-www/favicon.ico");
static BROKENITHM_FILES: phf::Map<&'static str, &'static [u8]> = phf_map! { static BROKENITHM_STR_FILES: phf::Map<&'static str, (&'static str, &'static str)> = phf_map! {
"app.js" => include_bytes!("./brokenithm-www/app.js"), "app.js" => (include_str!("./brokenithm-www/app.js"), "text/javascript"),
"config.js" => include_bytes!("./brokenithm-www/config.js"), "config.js" => (include_str!("./brokenithm-www/config.js"), "text/javascript"),
"favicon.ico" => include_bytes!("./brokenithm-www/favicon.ico"), "index-go.html" => (include_str!("./brokenithm-www/index-go.html"), "text/html"),
"index-go.html" => include_bytes!("./brokenithm-www/index-go.html"), "index.html" => (include_str!("./brokenithm-www/index.html"), "text/html"),
"index.html" => include_bytes!("./brokenithm-www/index.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<Response<Body>, Infallible> { async fn serve_file(path: &str) -> Result<Response<Body>, Infallible> {
@ -48,7 +51,7 @@ async fn serve_file(path: &str) -> Result<Response<Body>, Infallible> {
// pb.push(path); // pb.push(path);
// pb.clean(); // pb.clean();
// // println!("CWD {:?}", std::env::current_dir()); // println!("CWD {:?}", std::env::current_dir());
// match File::open(&pb).await { // match File::open(&pb).await {
// Ok(f) => { // Ok(f) => {
@ -59,9 +62,24 @@ async fn serve_file(path: &str) -> Result<Response<Body>, Infallible> {
// } // }
// Err(_) => error_response().await, // Err(_) => error_response().await,
// } // }
match BROKENITHM_FILES.get(path) {
Some(x) => Ok(Response::new(Body::from(*x))), match (
None => error_response().await, 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,
} }
} }

View File

@ -133,17 +133,19 @@ impl KeyboardOutput {
continue; continue;
} }
match (*n, *l) { match (*n, *l) {
(false, true) => { (true, false) => {
let inner: &mut KEYBDINPUT = unsafe { self.kb_buf[self.n_kb_buf as usize].u.ki_mut() }; let inner: &mut KEYBDINPUT = unsafe { self.kb_buf[self.n_kb_buf as usize].u.ki_mut() };
inner.wVk = keycode; inner.wVk = keycode;
inner.dwFlags = 0; inner.dwFlags = 0;
self.n_kb_buf += 1; 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() }; let inner: &mut KEYBDINPUT = unsafe { self.kb_buf[self.n_kb_buf as usize].u.ki_mut() };
inner.wVk = keycode; inner.wVk = keycode;
inner.dwFlags = KEYEVENTF_KEYUP; inner.dwFlags = KEYEVENTF_KEYUP;
self.n_kb_buf += 1; self.n_kb_buf += 1;
// println!("{} up", keycode);
} }
_ => {} _ => {}
} }