diff --git a/public/global.css b/public/global.css index 3a665ee..e120321 100644 --- a/public/global.css +++ b/public/global.css @@ -68,6 +68,7 @@ body { .header-timer { flex: 0 0 auto; + font-family: monospace; } /* main */ diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 2cf8b44..26e170f 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2955,6 +2955,7 @@ dependencies = [ "open", "palette", "path-clean", + "phf 0.10.1", "qrcode", "rusb", "serde", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 48af9fc..5fe8dc0 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -25,7 +25,6 @@ atomic_float = "0.1.0" spin_sleep = "1.0.0" tauri = { version = "1.0.0-beta.8", features = ["shell-open", "system-tray"] } - futures = "0.3.19" futures-util = "0.3.19" async-trait = "0.1.52" @@ -41,6 +40,7 @@ winapi = "0.3.9" ipconfig = "0.3.0" hyper = { version="0.14.16", features= ["server", "http1", "http2", "tcp", "stream", "runtime"] } +phf = { version = "0.10.1", features = ["macros"] } base64 = "0.13.0" image = "0.23.14" qrcode = { version="0.12.0", features= ["image"] } diff --git a/src-tauri/README.txt b/src-tauri/README.txt new file mode 100644 index 0000000..35457bb --- /dev/null +++ b/src-tauri/README.txt @@ -0,0 +1,6 @@ + _ _ _ _ _ + ___| (_) __| | ___ _ __| |__ ___(_)_ __ ___ +/ __| | |/ _` |/ _ \ '__| '_ \/ __| | '_ ` _ \ +\__ \ | | (_| | __/ | | | | \__ \ | | | | | | +|___/_|_|\__,_|\___|_| |_| |_|___/_|_| |_| |_| +=============================================== \ No newline at end of file diff --git a/src-tauri/res/.gitkeep b/src-tauri/res/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src-tauri/src/build.rs b/src-tauri/src/build.rs index 14b1182..44ad510 100644 --- a/src-tauri/src/build.rs +++ b/src-tauri/src/build.rs @@ -13,20 +13,25 @@ where // https://stackoverflow.com/a/68950006 let to = to.as_ref().to_path_buf(); - for path in fs::read_dir(from).unwrap() { - let path = path.unwrap().path(); - let to = to.clone().join(path.file_name().unwrap()); + match fs::read_dir(from) { + Ok(paths) => { + for path in paths { + let path = path.unwrap().path(); + let to = to.clone().join(path.file_name().unwrap()); - if path.is_file() { - fs::copy(&path, to).unwrap(); - } else if path.is_dir() { - if !to.exists() { - fs::create_dir(&to).unwrap(); + if path.is_file() { + fs::copy(&path, to).unwrap(); + } else if path.is_dir() { + if !to.exists() { + fs::create_dir(&to).unwrap(); + } + + copy_dir(&path, to); + } else { /* Skip other content */ + } } - - copy_dir(&path, to); - } else { /* Skip other content */ } + Err(_) => {} } } diff --git a/src-tauri/res/www/app.js b/src-tauri/src/slider_io/brokenithm-www/app.js similarity index 100% rename from src-tauri/res/www/app.js rename to src-tauri/src/slider_io/brokenithm-www/app.js diff --git a/src-tauri/res/www/config.js b/src-tauri/src/slider_io/brokenithm-www/config.js similarity index 100% rename from src-tauri/res/www/config.js rename to src-tauri/src/slider_io/brokenithm-www/config.js diff --git a/src-tauri/res/www/favicon.ico b/src-tauri/src/slider_io/brokenithm-www/favicon.ico similarity index 100% rename from src-tauri/res/www/favicon.ico rename to src-tauri/src/slider_io/brokenithm-www/favicon.ico diff --git a/src-tauri/res/www/index-go.html b/src-tauri/src/slider_io/brokenithm-www/index-go.html similarity index 100% rename from src-tauri/res/www/index-go.html rename to src-tauri/src/slider_io/brokenithm-www/index-go.html diff --git a/src-tauri/res/www/index.html b/src-tauri/src/slider_io/brokenithm-www/index.html similarity index 100% rename from src-tauri/res/www/index.html rename to src-tauri/src/slider_io/brokenithm-www/index.html diff --git a/src-tauri/res/www/src.js b/src-tauri/src/slider_io/brokenithm-www/src.js similarity index 100% rename from src-tauri/res/www/src.js rename to src-tauri/src/slider_io/brokenithm-www/src.js diff --git a/src-tauri/src/slider_io/brokenithm.rs b/src-tauri/src/slider_io/brokenithm.rs index 17b7017..9547ff7 100644 --- a/src-tauri/src/slider_io/brokenithm.rs +++ b/src-tauri/src/slider_io/brokenithm.rs @@ -8,16 +8,14 @@ use hyper::{ Body, Method, Request, Response, Server, StatusCode, }; use log::{error, info}; -use path_clean::PathClean; -use std::{convert::Infallible, env::current_exe, future::Future, net::SocketAddr}; +use phf::phf_map; +use std::{convert::Infallible, future::Future, net::SocketAddr}; use tokio::{ - fs::File, select, sync::mpsc, time::{sleep, Duration}, }; use tokio_tungstenite::WebSocketStream; -use tokio_util::codec::{BytesCodec, FramedRead}; use tungstenite::{handshake, Message}; use crate::slider_io::{controller_state::FullState, worker::AsyncJob}; @@ -33,23 +31,37 @@ 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"), +}; + async fn serve_file(path: &str) -> Result, Infallible> { - let mut pb = current_exe().unwrap(); - pb.pop(); - pb.push("res/www"); - pb.push(path); - pb.clean(); + // let mut pb = current_exe().unwrap(); + // pb.pop(); + // pb.push("res/www"); + // pb.push(path); + // pb.clean(); - // println!("CWD {:?}", std::env::current_dir()); + // // println!("CWD {:?}", std::env::current_dir()); - match File::open(&pb).await { - Ok(f) => { - info!("Serving file {:?}", pb); - let stream = FramedRead::new(f, BytesCodec::new()); - let body = Body::wrap_stream(stream); - Ok(Response::new(body)) - } - Err(_) => error_response().await, + // match File::open(&pb).await { + // Ok(f) => { + // info!("Serving file {:?}", pb); + // let stream = FramedRead::new(f, BytesCodec::new()); + // let body = Body::wrap_stream(stream); + // Ok(Response::new(body)) + // } + // Err(_) => error_response().await, + // } + match BROKENITHM_FILES.get(path) { + Some(x) => Ok(Response::new(Body::from(*x))), + None => error_response().await, } } diff --git a/src-tauri/src/slider_io/config.rs b/src-tauri/src/slider_io/config.rs index 1e32aa8..5a8a188 100644 --- a/src-tauri/src/slider_io/config.rs +++ b/src-tauri/src/slider_io/config.rs @@ -23,7 +23,7 @@ pub enum DeviceMode { pub enum OutputPolling { Sixty, Hundred, - ThreeHundred, + TwoHundredFifty, FiveHundred, Thousand, } @@ -33,7 +33,7 @@ impl OutputPolling { match s { "60" => Some(OutputPolling::Sixty), "100" => Some(OutputPolling::Hundred), - "330" => Some(OutputPolling::ThreeHundred), + "250" => Some(OutputPolling::TwoHundredFifty), "500" => Some(OutputPolling::FiveHundred), "1000" => Some(OutputPolling::Thousand), _ => None, @@ -42,11 +42,11 @@ impl OutputPolling { pub fn to_t_u64(&self) -> u64 { match self { - OutputPolling::Sixty => 16, - OutputPolling::Hundred => 10, - OutputPolling::ThreeHundred => 3, - OutputPolling::FiveHundred => 2, - OutputPolling::Thousand => 1, + OutputPolling::Sixty => 16666, + OutputPolling::Hundred => 10000, + OutputPolling::TwoHundredFifty => 4000, + OutputPolling::FiveHundred => 2000, + OutputPolling::Thousand => 1000, } } } diff --git a/src-tauri/src/slider_io/led.rs b/src-tauri/src/slider_io/led.rs index 5995d1d..4c8ba69 100644 --- a/src-tauri/src/slider_io/led.rs +++ b/src-tauri/src/slider_io/led.rs @@ -3,7 +3,6 @@ use palette::{FromColor, Hsv, Srgb}; use serialport::{ClearBuffer, SerialPort}; use std::{ ops::DerefMut, - thread, time::{Duration, Instant}, }; @@ -218,7 +217,7 @@ impl ThreadJob for LedJob { ); } // thread::sleep(Duration::from_millis(30)); - spin_sleep::sleep(Duration::from_millis(30)); + spin_sleep::sleep(Duration::from_micros(33333)); true } diff --git a/src-tauri/src/slider_io/output.rs b/src-tauri/src/slider_io/output.rs index f12da4e..bc68413 100644 --- a/src-tauri/src/slider_io/output.rs +++ b/src-tauri/src/slider_io/output.rs @@ -1,4 +1,4 @@ -use std::{thread, time::Duration}; +use std::time::Duration; use crate::slider_io::{ config::OutputMode, controller_state::FullState, gamepad::GamepadOutput, @@ -59,7 +59,7 @@ impl ThreadJob for OutputJob { self.handler.tick(&flat_controller_state); // thread::sleep(Duration::from_millis(self.t)); - spin_sleep::sleep(Duration::from_millis(self.t)); + spin_sleep::sleep(Duration::from_micros(self.t)); true } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index a803871..463e7f0 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -22,7 +22,7 @@ "icons/icon.ico" ], "resources": [ - "res/*" + "./README.txt" ], "externalBin": [], "copyright": "© 4yn 2022", diff --git a/src/App.svelte b/src/App.svelte index d62202f..4df92ca 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -202,7 +202,7 @@