chore: clean code.
This commit is contained in:
		| @@ -16,7 +16,7 @@ use crate::{ | ||||
|  | ||||
| use itertools::Itertools; | ||||
|  | ||||
| use super::{LedStripConfigGroup, SamplePointConfig, SamplePointMapper}; | ||||
| use super::{LedStripConfigGroup, SamplePointMapper}; | ||||
|  | ||||
| pub struct LedColorsPublisher { | ||||
|     sorted_colors_rx: Arc<RwLock<watch::Receiver<Vec<u8>>>>, | ||||
| @@ -68,7 +68,6 @@ impl LedColorsPublisher { | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
|             let mut start: tokio::time::Instant = tokio::time::Instant::now(); | ||||
|             let mut interval = tokio::time::interval(Duration::from_millis(66)); | ||||
|             let init_version = internal_tasks_version.read().await.clone(); | ||||
|  | ||||
| @@ -88,8 +87,6 @@ impl LedColorsPublisher { | ||||
|                     break; | ||||
|                 } | ||||
|  | ||||
|                 // log::info!("tick: {}ms", start.elapsed().as_millis()); | ||||
|                 start = tokio::time::Instant::now(); | ||||
|                 let colors = screenshot_manager::get_display_colors( | ||||
|                     display_id, | ||||
|                     &sample_points, | ||||
| @@ -104,7 +101,7 @@ impl LedColorsPublisher { | ||||
|  | ||||
|                 let colors = colors.unwrap(); | ||||
|  | ||||
|                 let color_len = colors.len(); | ||||
|                 // let color_len = colors.len(); | ||||
|  | ||||
|                 match display_colors_tx.send(( | ||||
|                     display_id, | ||||
| @@ -265,11 +262,8 @@ impl LedColorsPublisher { | ||||
|  | ||||
|                 let colors = rx.borrow().clone(); | ||||
|  | ||||
|                 let len = colors.len(); | ||||
|  | ||||
|                 match Self::send_colors(colors).await { | ||||
|                     Ok(_) => { | ||||
|                         // log::info!("colors sent. len: {}", len); | ||||
|                     } | ||||
|                     Err(err) => { | ||||
|                         warn!("colors send failed: {}", err); | ||||
|   | ||||
| @@ -8,12 +8,7 @@ mod rpc; | ||||
| pub mod screenshot; | ||||
| mod screenshot_manager; | ||||
|  | ||||
| use ambient_light::{ | ||||
|     Border, ColorCalibration, LedColorsPublisher, LedStripConfig, LedStripConfigGroup, | ||||
| }; | ||||
| use core_graphics::display::{ | ||||
|     kCGNullWindowID, kCGWindowImageDefault, kCGWindowListOptionOnScreenOnly, CGDisplay, | ||||
| }; | ||||
| use ambient_light::{Border, ColorCalibration, LedStripConfig, LedStripConfigGroup}; | ||||
| use display_info::DisplayInfo; | ||||
| use paris::{error, info, warn}; | ||||
| use screenshot::Screenshot; | ||||
|   | ||||
| @@ -10,11 +10,7 @@ use tokio::sync::{broadcast, watch, OnceCell}; | ||||
| use tokio::time::{self, Duration}; | ||||
|  | ||||
| use crate::screenshot::LedSamplePoints; | ||||
| use crate::{ | ||||
|     ambient_light::SamplePointMapper, | ||||
|     led_color::LedColor, | ||||
|     screenshot::Screenshot, | ||||
| }; | ||||
| use crate::{ambient_light::SamplePointMapper, led_color::LedColor, screenshot::Screenshot}; | ||||
|  | ||||
| pub fn take_screenshot(display_id: u32, scale_factor: f32) -> anyhow::Result<Screenshot> { | ||||
|     log::debug!("take_screenshot"); | ||||
| @@ -36,7 +32,6 @@ pub fn take_screenshot(display_id: u32, scale_factor: f32) -> anyhow::Result<Scr | ||||
|  | ||||
|     let bytes = buffer.bytes().to_owned(); | ||||
|  | ||||
|  | ||||
|     let cg_display = CGDisplay::new(display_id); | ||||
|     let bound_scale_factor = (cg_display.bounds().size.width / width as f64) as f32; | ||||
|  | ||||
| @@ -47,7 +42,7 @@ pub fn take_screenshot(display_id: u32, scale_factor: f32) -> anyhow::Result<Scr | ||||
|         bytes_per_row, | ||||
|         bytes, | ||||
|         scale_factor, | ||||
|         bound_scale_factor | ||||
|         bound_scale_factor, | ||||
|     )) | ||||
| } | ||||
|  | ||||
| @@ -60,7 +55,6 @@ pub fn get_display_colors( | ||||
|     let cg_display = CGDisplay::new(display_id); | ||||
|  | ||||
|     let mut colors = vec![]; | ||||
|     let start_at = std::time::Instant::now(); | ||||
|     for points in sample_points { | ||||
|         if points.len() == 0 { | ||||
|             continue; | ||||
| @@ -74,8 +68,8 @@ pub fn get_display_colors( | ||||
|         let (start_y, end_y) = (usize::min(start_y, end_y), usize::max(start_y, end_y)); | ||||
|  | ||||
|         let origin = CGPoint { | ||||
|             x: start_x as f64  * bound_scale_factor as f64 + cg_display.bounds().origin.x, | ||||
|             y: start_y as f64  * bound_scale_factor as f64  + cg_display.bounds().origin.y, | ||||
|             x: start_x as f64 * bound_scale_factor as f64 + cg_display.bounds().origin.x, | ||||
|             y: start_y as f64 * bound_scale_factor as f64 + cg_display.bounds().origin.y, | ||||
|         }; | ||||
|         let size = CGSize { | ||||
|             width: (end_x - start_x + 1) as f64, | ||||
| @@ -116,13 +110,6 @@ pub fn get_display_colors( | ||||
|         colors.append(&mut part_colors); | ||||
|     } | ||||
|  | ||||
|     // if display_id == 4849664 { | ||||
|     //     log::info!( | ||||
|     //         "======= get_display_colors {} took {}ms", | ||||
|     //         display_id, | ||||
|     //         start_at.elapsed().as_millis() | ||||
|     //     ); | ||||
|     // } | ||||
|     Ok(colors) | ||||
| } | ||||
|  | ||||
| @@ -166,7 +153,6 @@ impl ScreenshotManager { | ||||
|                 return; | ||||
|             } | ||||
|             let mut interval = time::interval(Duration::from_millis(1000)); | ||||
|             let mut start = tokio::time::Instant::now(); | ||||
|  | ||||
|             let screenshot = screenshot.unwrap(); | ||||
|             let (screenshot_tx, screenshot_rx) = watch::channel(screenshot); | ||||
| @@ -179,7 +165,6 @@ impl ScreenshotManager { | ||||
|             let merged_screenshot_tx = merged_screenshot_tx.read().await.clone(); | ||||
|  | ||||
|             loop { | ||||
|                 start = tokio::time::Instant::now(); | ||||
|                 Self::take_screenshot_loop( | ||||
|                     display_id, | ||||
|                     scale_factor, | ||||
| @@ -205,10 +190,12 @@ impl ScreenshotManager { | ||||
|         if let Ok(screenshot) = screenshot { | ||||
|             match merged_screenshot_tx.send(screenshot.clone()) { | ||||
|                 Ok(_) => { | ||||
|                     log::info!("take_screenshot_loop: merged_screenshot_tx.send success. display#{}", display_id); | ||||
|                     log::info!( | ||||
|                         "take_screenshot_loop: merged_screenshot_tx.send success. display#{}", | ||||
|                         display_id | ||||
|                     ); | ||||
|                 } | ||||
|                 Err(err) => { | ||||
|                     // warn!("take_screenshot_loop: merged_screenshot_tx.send failed. display#{}. err: {}", display_id, err); | ||||
|                 Err(_) => { | ||||
|                 } | ||||
|             } | ||||
|             screenshot_tx.send(screenshot).unwrap(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user