pref: 移除旧的截图图像发送到前端的逻辑。

This commit is contained in:
Ivan Li 2023-03-20 09:35:02 +08:00
parent 85ef261c51
commit 9ed2fa8b53
3 changed files with 17 additions and 20 deletions

View File

@ -167,12 +167,9 @@ async fn main() {
subscribe_encoded_screenshot_updated subscribe_encoded_screenshot_updated
]) ])
.register_uri_scheme_protocol("ambient-light", move |_app, request| { .register_uri_scheme_protocol("ambient-light", move |_app, request| {
info!("request: {:?}", request.uri());
// prepare our response
let response = ResponseBuilder::new().header("Access-Control-Allow-Origin", "*"); let response = ResponseBuilder::new().header("Access-Control-Allow-Origin", "*");
// get the file path
let uri = request.uri();
let uri = request.uri();
let uri = percent_encoding::percent_decode_str(uri) let uri = percent_encoding::percent_decode_str(uri)
.decode_utf8() .decode_utf8()
.unwrap() .unwrap()
@ -226,7 +223,7 @@ async fn main() {
.unwrap(); .unwrap();
(screenshot.width as f32 / width as f32, width, height) (screenshot.width as f32 / width as f32, width, height)
} else { } else {
info!("scale by scale_factor"); log::debug!("scale by scale_factor");
let scale_factor = screenshot.scale_factor; let scale_factor = screenshot.scale_factor;
( (
scale_factor, scale_factor,
@ -234,7 +231,7 @@ async fn main() {
(screenshot.height as f32 / scale_factor) as u32, (screenshot.height as f32 / scale_factor) as u32,
) )
}; };
info!( log::debug!(
"scale by query. width: {}, height: {}, scale_factor: {}, len: {}", "scale by query. width: {}, height: {}, scale_factor: {}, len: {}",
width, width,
height, height,

View File

@ -38,5 +38,5 @@ pub struct ScreenshotPayload {
pub display_id: u32, pub display_id: u32,
pub height: u32, pub height: u32,
pub width: u32, pub width: u32,
pub base64_image: String, // pub base64_image: String,
} }

View File

@ -90,7 +90,7 @@ impl ScreenshotManager {
} }
loop { loop {
Self::take_screenshot_loop(display_id, scale_factor, &tx).await; Self::take_screenshot_loop(display_id, scale_factor, &tx).await;
tokio::time::sleep(std::time::Duration::from_millis(100)).await; tokio::time::sleep(std::time::Duration::from_millis(20)).await;
} }
}); });
@ -150,31 +150,31 @@ impl ScreenshotManager {
break; break;
} }
let screenshot = rx.borrow().clone(); let screenshot = rx.borrow().clone();
let base64_image = Self::encode_screenshot_to_base64(&screenshot).await; // let base64_image = Self::encode_screenshot_to_base64(&screenshot).await;
let height = screenshot.height; let height = screenshot.height;
let width = screenshot.width; let width = screenshot.width;
if base64_image.is_err() { // if base64_image.is_err() {
error!( // error!(
"subscribe_encoded_screenshot_updated: encode_screenshot_to_base64 error {}", // "subscribe_encoded_screenshot_updated: encode_screenshot_to_base64 error {}",
base64_image.err().unwrap() // base64_image.err().unwrap()
); // );
continue; // continue;
} // }
let base64_image = base64_image.unwrap(); // let base64_image = base64_image.unwrap();
for window in windows.unwrap().into_iter() { for window in windows.unwrap().into_iter() {
let base64_image = base64_image.clone(); // let base64_image = base64_image.clone();
let payload = ScreenshotPayload { let payload = ScreenshotPayload {
display_id, display_id,
base64_image, // base64_image,
height, height,
width, width,
}; };
if let Err(err) = window.emit("encoded-screenshot-updated", payload) { if let Err(err) = window.emit("encoded-screenshot-updated", payload) {
error!("subscribe_encoded_screenshot_updated: emit error {}", err) error!("subscribe_encoded_screenshot_updated: emit error {}", err)
} else { } else {
info!( log::debug!(
"subscribe_encoded_screenshot_updated: emit success. display#{}", "subscribe_encoded_screenshot_updated: emit success. display#{}",
display_id display_id
) )