Cargo clippy

This commit is contained in:
Jovi Hsu 2022-09-27 00:29:06 +00:00
parent 1c5a0518e9
commit 2557e9e897
3 changed files with 40 additions and 58 deletions

View File

@ -162,7 +162,7 @@ fn vnc_out_handler(ws: &WebSocket, vnc: &Vnc) {
vnc::VncOutput::Err(err) => { vnc::VncOutput::Err(err) => {
console_log!("Err {}", err); console_log!("Err {}", err);
} }
vnc::VncOutput::WsBuf(buf) => match ws.send_with_u8_array(&buf) { vnc::VncOutput::WsBuf(buf) => match ws.send_with_u8_array(buf) {
Ok(_) => {} Ok(_) => {}
Err(err) => console_log!("error sending message: {:?}", err), Err(err) => console_log!("error sending message: {:?}", err),
}, },
@ -213,7 +213,7 @@ fn vnc_out_handler(ws: &WebSocket, vnc: &Vnc) {
} }
} }
vnc::VncOutput::SetCanvas(x, y) => { vnc::VncOutput::SetCanvas(x, y) => {
set_canvas(&vnc, *x, *y); set_canvas(vnc, *x, *y);
let vnc_cloned = vnc.clone(); let vnc_cloned = vnc.clone();
let ws_cloned = ws.clone(); let ws_cloned = ws.clone();
@ -269,7 +269,6 @@ fn start_websocket() -> Result<(), JsValue> {
let vnc = Vnc::new(); let vnc = Vnc::new();
let cloned_vnc = vnc.clone();
// on message // on message
let cloned_ws = ws.clone(); let cloned_ws = ws.clone();
@ -277,8 +276,8 @@ fn start_websocket() -> Result<(), JsValue> {
if let Ok(abuf) = e.data().dyn_into::<js_sys::ArrayBuffer>() { if let Ok(abuf) = e.data().dyn_into::<js_sys::ArrayBuffer>() {
let array = js_sys::Uint8Array::new(&abuf); let array = js_sys::Uint8Array::new(&abuf);
// let mut canvas_ctx = None; // let mut canvas_ctx = None;
cloned_vnc.do_input(array.to_vec()); vnc.do_input(array.to_vec());
vnc_out_handler(&cloned_ws, &cloned_vnc); vnc_out_handler(&cloned_ws, &vnc);
} else { } else {
console_log!("message event, received Unknown: {:?}", e.data()); console_log!("message event, received Unknown: {:?}", e.data());
} }
@ -306,5 +305,6 @@ fn start_websocket() -> Result<(), JsValue> {
#[wasm_bindgen(start)] #[wasm_bindgen(start)]
pub fn run_app() -> Result<(), JsValue> { pub fn run_app() -> Result<(), JsValue> {
utils::set_panic_hook();
start_websocket() start_websocket()
} }

View File

@ -1,5 +1,5 @@
mod des; mod des;
mod vnc; mod vnc_impl;
mod x11cursor; mod x11cursor;
mod x11keyboard; mod x11keyboard;
@ -11,8 +11,6 @@ pub enum MouseEventType {
use std::{rc::Rc, sync::Mutex}; use std::{rc::Rc, sync::Mutex};
use crate::{console_log, log};
pub struct CanvasData { pub struct CanvasData {
pub type_: u32, pub type_: u32,
pub x: u16, pub x: u16,
@ -32,50 +30,45 @@ pub enum VncOutput {
} }
pub struct Vnc { pub struct Vnc {
inner: Rc<Mutex<vnc::Vnc>>, inner: Rc<Mutex<vnc_impl::Vnc>>,
} }
impl Vnc { impl Vnc {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
inner: Rc::new(Mutex::new(vnc::Vnc::new())), inner: Rc::new(Mutex::new(vnc_impl::Vnc::new())),
} }
} }
pub fn do_input(&self, input: Vec<u8>) { pub fn do_input(&self, input: Vec<u8>) {
self.inner.as_ref().lock().unwrap().do_input(input); self.inner.lock().unwrap().do_input(input);
} }
pub fn get_output(&self) -> Vec<VncOutput> { pub fn get_output(&self) -> Vec<VncOutput> {
self.inner.as_ref().lock().unwrap().get_output() self.inner.lock().unwrap().get_output()
} }
pub fn set_credential(&self, username: &str, password: &str) { pub fn set_credential(&self, username: &str, password: &str) {
self.inner self.inner
.as_ref()
.lock() .lock()
.unwrap() .unwrap()
.set_credential(username, password); .set_credential(username, password);
} }
pub fn set_clipboard(&self, text: &str) { pub fn set_clipboard(&self, text: &str) {
self.inner.as_ref().lock().unwrap().set_clipboard(text); self.inner.lock().unwrap().set_clipboard(text);
} }
pub fn require_frame(&self, incremental: u8) { pub fn require_frame(&self, incremental: u8) {
self.inner self.inner.lock().unwrap().require_frame(incremental);
.as_ref()
.lock()
.unwrap()
.require_frame(incremental);
} }
pub fn key_press(&self, key: web_sys::KeyboardEvent, down: bool) { pub fn key_press(&self, key: web_sys::KeyboardEvent, down: bool) {
self.inner.as_ref().lock().unwrap().key_press(key, down); self.inner.lock().unwrap().key_press(key, down);
} }
pub fn mouse_event(&self, mouse: web_sys::MouseEvent, et: MouseEventType) { pub fn mouse_event(&self, mouse: web_sys::MouseEvent, et: MouseEventType) {
self.inner.as_ref().lock().unwrap().mouse_event(mouse, et); self.inner.lock().unwrap().mouse_event(mouse, et);
} }
} }

View File

@ -104,7 +104,6 @@ impl Vnc {
} }
} }
pub fn do_input(&mut self, input: Vec<u8>) { pub fn do_input(&mut self, input: Vec<u8>) {
// ConsoleService::info(&format!( // ConsoleService::info(&format!(
// "VNC input {}, left {}, require {}", // "VNC input {}, left {}, require {}",
@ -135,9 +134,8 @@ impl Vnc {
self.outbuf.clear(); self.outbuf.clear();
} }
return out; return out;
} else { };
return Vec::new(); Vec::new()
}
} }
pub fn set_credential(&mut self, _username: &str, password: &str) { pub fn set_credential(&mut self, _username: &str, password: &str) {
@ -544,11 +542,23 @@ impl Vnc {
// } // }
// } // }
self.read_exact_vec(&mut image_data, self.require); self.read_exact_vec(&mut image_data, self.require);
for y in 0..rect.height { let mut y = 0;
for x in 0..rect.width { let mut x = 0;
// for y in 0..rect.height {
// for x in 0..rect.width {
// let idx = (y as usize * rect.width as usize + x as usize) * 4;
// image_data.swap(idx, idx + 2)
// }
// }
while y < rect.height {
while x < rect.width {
let idx = (y as usize * rect.width as usize + x as usize) * 4; let idx = (y as usize * rect.width as usize + x as usize) * 4;
image_data.swap(idx, idx + 2) image_data.swap(idx, idx + 2);
x += 1;
} }
x = 0;
y += 1;
} }
} }
1 => { 1 => {
@ -557,15 +567,14 @@ impl Vnc {
} }
_ => unimplemented!(), _ => unimplemented!(),
} }
self.outs self.outs.push(VncOutput::RenderCanvas(CanvasData {
.push(VncOutput::RenderCanvas(CanvasData { type_: rect.encoding_type,
type_: rect.encoding_type, x: rect.x,
x: rect.x, y: rect.y,
y: rect.y, width: rect.width,
width: rect.width, height: rect.height,
height: rect.height, data: image_data,
data: image_data, }));
}));
self.num_rect_left -= 1; self.num_rect_left -= 1;
if 0 == self.num_rect_left { if 0 == self.num_rect_left {
self.msg_handling = ServerMessage::None; self.msg_handling = ServerMessage::None;
@ -708,7 +717,7 @@ impl Vnc {
// 1 CARD8 green-shift // 1 CARD8 green-shift
// 1 CARD8 blue-shift // 1 CARD8 blue-shift
// 1 CARD8 padding // 1 CARD8 padding
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy, Default)]
struct PixelFormat { struct PixelFormat {
// the number of bits used for each pixel value on the wire // the number of bits used for each pixel value on the wire
// 8, 16, 32(usually) only // 8, 16, 32(usually) only
@ -788,26 +797,6 @@ impl From<&[u8; 16]> for PixelFormat {
} }
} }
impl Default for PixelFormat {
fn default() -> Self {
Self {
bits_per_pixel: 0,
depth: 0,
big_endian_flag: 0,
true_color_flag: 0,
red_max: 0,
green_max: 0,
blue_max: 0,
red_shift: 0,
green_shift: 0,
blue_shift: 0,
padding_1: 0,
padding_2: 0,
padding_3: 0,
}
}
}
struct VncRect { struct VncRect {
x: u16, x: u16,
y: u16, y: u16,