chore: 代码清理。

This commit is contained in:
Ivan Li 2023-04-01 18:43:49 +08:00
parent 47e30ec94a
commit d053185cc2
7 changed files with 16 additions and 120 deletions

View File

@ -1,3 +1,6 @@
{
"files.autoSave": "onWindowChange"
"files.autoSave": "onWindowChange",
"cSpell.words": [
"Itertools"
]
}

View File

@ -1,8 +1,8 @@
use std::{borrow::BorrowMut, collections::HashMap, sync::Arc, time::Duration};
use std::sync::Arc;
use paris::warn;
use tauri::async_runtime::{Mutex, RwLock};
use tokio::{sync::watch, time::sleep};
use tokio::sync::watch;
use crate::{
ambient_light::{config, ConfigManager},

View File

@ -159,7 +159,8 @@ impl Manager {
let rpc = rpc::Manager::global().await;
rpc.publish_desktop_cmd(
format!("display{}/brightness", display_brightness.display_index).as_str(),
format!("display{}/brightness", display_brightness.display_index)
.as_str(),
target.to_be_bytes().to_vec(),
)
.await;

View File

@ -4,10 +4,7 @@ use std::sync::Arc;
use serde::{Deserialize, Serialize};
use tauri::async_runtime::RwLock;
use crate::{
ambient_light::{LedStripConfig, LedStripConfigOfDisplays},
led_color::LedColor,
};
use crate::{ambient_light::LedStripConfig, led_color::LedColor};
#[derive(Debug, Clone)]
pub struct Screenshot {
@ -41,10 +38,7 @@ impl Screenshot {
}
}
pub fn get_sample_points(
&self,
config: &LedStripConfig,
) -> Vec<LedSamplePoints> {
pub fn get_sample_points(&self, config: &LedStripConfig) -> Vec<LedSamplePoints> {
let height = self.height as usize;
let width = self.width as usize;
@ -82,93 +76,6 @@ impl Screenshot {
}
}
// fn get_sample_points(config: DisplayConfig) -> ScreenSamplePoints {
// let top = match config.led_strip_of_borders.top {
// Some(led_strip_config) => Self::get_one_edge_sample_points(
// config.display_height / 8,
// config.display_width,
// led_strip_config.len,
// 1,
// ),
// None => {
// vec![]
// }
// };
// let bottom: Vec<LedSamplePoints> = match config.led_strip_of_borders.bottom {
// Some(led_strip_config) => {
// let points = Self::get_one_edge_sample_points(
// config.display_height / 9,
// config.display_width,
// led_strip_config.len,
// 5,
// );
// points
// .into_iter()
// .map(|groups| -> Vec<Point> {
// groups
// .into_iter()
// .map(|(x, y)| (x, config.display_height - y))
// .collect()
// })
// .collect()
// }
// None => {
// vec![]
// }
// };
// let left: Vec<LedSamplePoints> = match config.led_strip_of_borders.left {
// Some(led_strip_config) => {
// let points = Self::get_one_edge_sample_points(
// config.display_width / 16,
// config.display_height,
// led_strip_config.len,
// 5,
// );
// points
// .into_iter()
// .map(|groups| -> Vec<Point> {
// groups.into_iter().map(|(x, y)| (y, x)).collect()
// })
// .collect()
// }
// None => {
// vec![]
// }
// };
// let right: Vec<LedSamplePoints> = match config.led_strip_of_borders.right {
// Some(led_strip_config) => {
// let points = Self::get_one_edge_sample_points(
// config.display_width / 16,
// config.display_height,
// led_strip_config.len,
// 5,
// );
// points
// .into_iter()
// .map(|groups| -> Vec<Point> {
// groups
// .into_iter()
// .map(|(x, y)| (config.display_width - y, x))
// .collect()
// })
// .collect()
// }
// None => {
// vec![]
// }
// };
// ScreenSamplePoints {
// top,
// bottom,
// left,
// right,
// }
// }
fn get_one_edge_sample_points(
width: usize,
length: usize,
@ -258,13 +165,15 @@ impl Screenshot {
r += bitmap[position + 2] as f64;
}
let color = LedColor::new((r / len) as u8, (g / len) as u8, (b / len) as u8);
// paris::info!("color: {:?}", color.get_rgb());
colors.push(color);
}
colors
}
pub async fn get_colors_by_sample_points(&self, points: &Vec<LedSamplePoints>) -> Vec<LedColor> {
pub async fn get_colors_by_sample_points(
&self,
points: &Vec<LedSamplePoints>,
) -> Vec<LedColor> {
let bytes = self.bytes.read().await;
Self::get_one_edge_colors(points, &bytes, self.bytes_per_row)

View File

@ -1,5 +1,4 @@
import { Component, createMemo, ParentComponent } from 'solid-js';
import { LedStripConfigOfBorders } from '../models/display-config';
import { Component, createMemo } from 'solid-js';
import { DisplayInfo } from '../models/display-info.model';
import { displayStore } from '../stores/display.store';
import { ledStripStore } from '../stores/led-strip.store';

View File

@ -1,14 +1,4 @@
import {
Component,
createContext,
createEffect,
createMemo,
createSignal,
For,
JSX,
onCleanup,
untrack,
} from 'solid-js';
import { Component, createContext, createEffect, createSignal, For } from 'solid-js';
import { LedStripConfig, LedStripPixelMapper } from '../models/led-strip-config';
import { ledStripStore } from '../stores/led-strip.store';

View File

@ -14,12 +14,6 @@ type ScreenViewProps = {
displayId: number;
} & JSX.HTMLAttributes<HTMLDivElement>;
async function subscribeScreenshotUpdate(displayId: number) {
await invoke('subscribe_encoded_screenshot_updated', {
displayId,
});
}
export const ScreenView: Component<ScreenViewProps> = (props) => {
const [localProps, rootProps] = splitProps(props, ['displayId']);
let canvas: HTMLCanvasElement;