chore: 更好地按帧发送灯条数据。

This commit is contained in:
2023-01-15 20:47:21 +08:00
parent a12c503e81
commit a3e2b5a234
4 changed files with 383 additions and 5 deletions

View File

@@ -3,7 +3,7 @@ use once_cell::sync::OnceCell;
use paris::{error, info};
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, sync::Arc, time::Duration};
use std::{collections::{HashMap, HashSet}, sync::Arc, time::Duration};
use tauri::async_runtime::RwLock;
use tokio::{
sync::mpsc,
@@ -108,6 +108,25 @@ impl CoreManager {
futs.push(fut);
}
let total_colors_count = configs
.iter()
.flat_map(|c| {
vec![
c.led_strip_of_borders.top,
c.led_strip_of_borders.bottom,
c.led_strip_of_borders.left,
c.led_strip_of_borders.right,
]
})
.flat_map(|l| match l {
Some(l) => (l.global_start_position.min(l.global_end_position)
..l.global_start_position.max(l.global_end_position))
.collect(),
None => {
vec![]
}
}).collect::<HashSet<_>>()
.len();
tokio::spawn(async move {
let mut global_colors = HashMap::new();
while let Some(screenshot) = rx.recv().await {
@@ -127,7 +146,7 @@ impl CoreManager {
start_at.elapsed()
);
if global_colors.len() == 60 {
if global_colors.len() >= total_colors_count {
let mut colors = vec![];
for index in 0..global_colors.len() {
colors.push(*global_colors.get(&index).unwrap());

View File

@@ -27,11 +27,13 @@ impl Picker {
SCREEN_COLOR_PICKER
.get_or_init(|| async {
let configs = config::Manager::global().get_config().await.display_configs;
info!("Global Picker use configs. {:?}", configs);
Picker {
screens: Arc::new(Mutex::new(vec![])),
screenshots: Arc::new(Mutex::new(vec![])),
display_configs: Arc::new(Mutex::new(
config::Manager::global().get_config().await.display_configs,
configs,
)),
}
})
@@ -39,12 +41,12 @@ impl Picker {
}
pub async fn list_displays(&self) -> anyhow::Result<Vec<ScreenshotDto>> {
let mut configs = self.display_configs.lock().await;
let mut configs = vec![];
let displays = Display::all()
.map_err(|error| anyhow::anyhow!("Can not get all of displays. {}", error))?;
configs.clear();
// configs.clear();
let mut futs = FuturesUnordered::new();
for (index, display) in displays.iter().enumerate() {