From 3e54d304981a5356de56292e9a8e18a545e12813 Mon Sep 17 00:00:00 2001 From: Ivan Li Date: Sun, 26 Mar 2023 15:54:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BC=A9=E6=94=BE=E7=9A=84=E5=B1=8F?= =?UTF-8?q?=E5=B9=95=EF=BC=8C=E7=81=AF=E6=9D=A1=E9=A2=9C=E8=89=B2=E9=A2=84?= =?UTF-8?q?=E8=A7=88=E6=95=88=E6=9E=9C=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/main.rs | 27 +++++++++++---------------- src-tauri/src/screenshot.rs | 2 +- src/components/display-view.tsx | 8 ++++---- src/components/led-strip-part.tsx | 18 ++++++++---------- 4 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index ed4c811..fc3dee4 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -98,24 +98,19 @@ async fn write_led_strip_configs( async fn get_led_strips_sample_points( config: LedStripConfig, ) -> Result, String> { - let displays = DisplayInfo::all().map_err(|e| { - error!("can not read led strip config: {}", e); - e.to_string() - }); - let display = displays?.into_iter().find(|d| d.id == config.display_id); - - if let None = display { + let screenshot_manager = ScreenshotManager::global().await; + let channels = screenshot_manager.channels.read().await; + if let Some(rx) = channels.get(&config.display_id) { + let rx = rx.clone(); + let screenshot = rx.borrow().clone(); + let width = screenshot.width; + let height = screenshot.height; + let sample_points = + Screenshot::get_sample_point(&config, width as usize, height as usize); + Ok(sample_points) + } else { return Err(format!("display not found: {}", config.display_id)); } - - let display = display.unwrap(); - - let config = screenshot::Screenshot::get_sample_point( - config, - display.width as usize, - display.height as usize, - ); - Ok(config) } #[tauri::command] diff --git a/src-tauri/src/screenshot.rs b/src-tauri/src/screenshot.rs index 9207ca1..78ee7cf 100644 --- a/src-tauri/src/screenshot.rs +++ b/src-tauri/src/screenshot.rs @@ -42,7 +42,7 @@ impl Screenshot { } pub fn get_sample_point( - config: LedStripConfig, + config: &LedStripConfig, width: usize, height: usize, ) -> Vec { diff --git a/src/components/display-view.tsx b/src/components/display-view.tsx index e330d4f..61fb24d 100644 --- a/src/components/display-view.tsx +++ b/src/components/display-view.tsx @@ -45,19 +45,19 @@ export const DisplayView: Component = (props) => { class="absolute bg-slate-50/10 top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 rounded backdrop-blur w-1/3 min-w-[300px] text-black" /> c.border === 'Top')} /> c.border === 'Left')} /> c.border === 'Right')} /> c.border === 'Bottom')} /> diff --git a/src/components/led-strip-part.tsx b/src/components/led-strip-part.tsx index 34060e4..465b472 100644 --- a/src/components/led-strip-part.tsx +++ b/src/components/led-strip-part.tsx @@ -34,10 +34,14 @@ export const Pixel: Component = (props) => { })); return (
+ > +
+
); }; @@ -52,6 +56,7 @@ export const LedStripPart: Component = (props) => { if (!localProps.config || !samplePoints) { return; } + let pendingCount = 0; const unlisten = listen<{ base64_image: string; @@ -67,12 +72,6 @@ export const LedStripPart: Component = (props) => { } pendingCount++; - console.log({ - samplePoints, - displayId: event.payload.display_id, - border: localProps.config!.border, - }); - invoke('get_one_edge_colors', { samplePoints, displayId: event.payload.display_id, @@ -107,7 +106,6 @@ export const LedStripPart: Component = (props) => { if (_colors) { return {(item) => }; } else if (localProps.config) { - return null; return ( {() => }