mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-05-03 02:39:58 -07:00
send bytes to framebuffer instead of image
This commit is contained in:
@@ -33,6 +33,7 @@ use std::time::Duration;
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::sync::{RwLock, oneshot};
|
||||
use std::sync::Arc;
|
||||
use include_dir::{include_dir, Dir};
|
||||
|
||||
// Runs the axum server, taking all the elements needed to build up our
|
||||
// ServerState and a oneshot Receiver that'll fire when it's time to shutdown
|
||||
@@ -123,14 +124,16 @@ fn run_ctrl_c_thread(
|
||||
}
|
||||
|
||||
async fn update_ui(task_tracker: &TaskTracker, config: &config::Config, mut ui_shutdown_rx: oneshot::Receiver<()>){
|
||||
let image = match config.ui_level {
|
||||
static IMAGE_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/static/images/");
|
||||
let img_name = match config.ui_level {
|
||||
0 => {info!("silent UI!"); return},
|
||||
1 => "subtle.png",
|
||||
2 => "orca.gif",
|
||||
_ => "orca.gif"
|
||||
};
|
||||
let img = IMAGE_DIR.get_file(img_name).unwrap();
|
||||
|
||||
info!("spawning UI with {}", image);
|
||||
info!("spawning UI with {:?}", img.path());
|
||||
task_tracker.spawn_blocking(move || {
|
||||
let mut fb: Framebuffer = Framebuffer::new();
|
||||
loop {
|
||||
@@ -140,10 +143,14 @@ async fn update_ui(task_tracker: &TaskTracker, config: &config::Config, mut ui_
|
||||
break;
|
||||
},
|
||||
Err(TryRecvError::Empty) => {},
|
||||
Err(e) => panic!("what the fuck {e}")
|
||||
Err(e) => panic!("error receiving shutdown message: {e}")
|
||||
|
||||
}
|
||||
fb.draw_img(image);
|
||||
if img_name.ends_with(".gif"){
|
||||
fb.draw_gif(img.contents());
|
||||
} else {
|
||||
fb.draw_img(img.contents());
|
||||
}
|
||||
sleep(Duration::from_millis(100));
|
||||
}
|
||||
}).await.unwrap();
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
use image::{codecs::gif::GifDecoder, imageops::FilterType, AnimationDecoder, DynamicImage};
|
||||
use std::{io::Cursor, time::Duration};
|
||||
use include_dir::{include_dir, Dir};
|
||||
|
||||
const FB_PATH:&str = "/dev/fb0";
|
||||
static IMAGE_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/static/images/");
|
||||
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
@@ -55,22 +53,21 @@ impl Framebuffer<'_>{
|
||||
}
|
||||
|
||||
|
||||
pub fn draw_img(&mut self, img_name: &str) {
|
||||
let img = IMAGE_DIR.get_file(img_name).unwrap();
|
||||
if img_name.ends_with(".gif") {
|
||||
// this is dumb and i'm sure there's a better way to loop this
|
||||
let cursor = Cursor::new(img.contents());
|
||||
let decoder = GifDecoder::new(cursor).unwrap();
|
||||
for maybe_frame in decoder.into_frames() {
|
||||
let frame = maybe_frame.unwrap();
|
||||
let (numerator, _) = frame.delay().numer_denom_ms();
|
||||
let img = DynamicImage::from(frame.into_buffer());
|
||||
self.write(img);
|
||||
std::thread::sleep(Duration::from_millis(numerator as u64));
|
||||
}
|
||||
} else {
|
||||
let img = image::load_from_memory(img.contents()).unwrap();
|
||||
pub fn draw_gif(&mut self, img_buffer: &[u8]) {
|
||||
// this is dumb and i'm sure there's a better way to loop this
|
||||
let cursor = Cursor::new(img_buffer);
|
||||
let decoder = GifDecoder::new(cursor).unwrap();
|
||||
for maybe_frame in decoder.into_frames() {
|
||||
let frame = maybe_frame.unwrap();
|
||||
let (numerator, _) = frame.delay().numer_denom_ms();
|
||||
let img = DynamicImage::from(frame.into_buffer());
|
||||
self.write(img);
|
||||
std::thread::sleep(Duration::from_millis(numerator as u64));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_img(&mut self, img_buffer: &[u8]) {
|
||||
let img = image::load_from_memory(img_buffer).unwrap();
|
||||
self.write(img);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user