feat: 支持将色彩校准的值写入本地配置文件。
This commit is contained in:
@ -5,7 +5,7 @@ use paris::{error, info};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tauri::api::path::config_dir;
|
||||
|
||||
use crate::screenshot::{self, LedSamplePoints};
|
||||
use crate::screenshot::LedSamplePoints;
|
||||
|
||||
const CONFIG_FILE_NAME: &str = "cc.ivanli.ambient_light/led_strip_config.toml";
|
||||
|
||||
@ -26,10 +26,18 @@ pub struct LedStripConfig {
|
||||
pub len: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Serialize, Deserialize, Debug)]
|
||||
pub struct ColorCalibration {
|
||||
r: f32,
|
||||
g: f32,
|
||||
b: f32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||
pub struct LedStripConfigGroup {
|
||||
pub strips: Vec<LedStripConfig>,
|
||||
pub mappers: Vec<SamplePointMapper>,
|
||||
pub color_calibration: ColorCalibration,
|
||||
}
|
||||
|
||||
impl LedStripConfigGroup {
|
||||
@ -115,7 +123,17 @@ impl LedStripConfigGroup {
|
||||
})
|
||||
}
|
||||
}
|
||||
Ok(Self { strips, mappers })
|
||||
let color_calibration = ColorCalibration {
|
||||
r: 1.0,
|
||||
g: 1.0,
|
||||
b: 1.0,
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
strips,
|
||||
mappers,
|
||||
color_calibration,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ use tokio::sync::OnceCell;
|
||||
|
||||
use crate::ambient_light::{config, LedStripConfigGroup};
|
||||
|
||||
use super::{Border, SamplePointMapper};
|
||||
use super::{Border, SamplePointMapper, ColorCalibration};
|
||||
|
||||
pub struct ConfigManager {
|
||||
config: Arc<RwLock<LedStripConfigGroup>>,
|
||||
@ -223,4 +223,15 @@ impl ConfigManager {
|
||||
) -> tokio::sync::watch::Receiver<LedStripConfigGroup> {
|
||||
self.config_update_receiver.clone()
|
||||
}
|
||||
|
||||
pub async fn set_color_calibration(&self, color_calibration: ColorCalibration) -> anyhow::Result<()> {
|
||||
let config = self.config.write().await;
|
||||
|
||||
let mut cloned_config = config.clone();
|
||||
cloned_config.color_calibration = color_calibration;
|
||||
|
||||
drop(config);
|
||||
|
||||
self.update(&cloned_config).await
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ impl LedColorsPublisher {
|
||||
warn!("Failed to send sorted colors: {}", err);
|
||||
}
|
||||
};
|
||||
log::info!("tick: {}ms", start.elapsed().as_millis());
|
||||
log::debug!("tick: {}ms", start.elapsed().as_millis());
|
||||
start = tokio::time::Instant::now();
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,9 @@ mod rpc;
|
||||
pub mod screenshot;
|
||||
mod screenshot_manager;
|
||||
|
||||
use ambient_light::{Border, LedColorsPublisher, LedStripConfig, LedStripConfigGroup};
|
||||
use ambient_light::{
|
||||
Border, ColorCalibration, LedColorsPublisher, LedStripConfig, LedStripConfigGroup,
|
||||
};
|
||||
use core_graphics::display::{
|
||||
kCGNullWindowID, kCGWindowImageDefault, kCGWindowListOptionOnScreenOnly, CGDisplay,
|
||||
};
|
||||
@ -145,14 +147,14 @@ async fn send_colors(buffer: Vec<u8>) -> Result<(), String> {
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn move_strip_part(display_id: u32, border: Border, target_start: usize) -> Result<(), String> {
|
||||
async fn move_strip_part(
|
||||
display_id: u32,
|
||||
border: Border,
|
||||
target_start: usize,
|
||||
) -> Result<(), String> {
|
||||
let config_manager = ambient_light::ConfigManager::global().await;
|
||||
config_manager
|
||||
.move_strip_part(
|
||||
display_id,
|
||||
border,
|
||||
target_start,
|
||||
)
|
||||
.move_strip_part(display_id, border, target_start)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
error!("can not move strip part: {}", e);
|
||||
@ -172,6 +174,18 @@ async fn reverse_led_strip_part(display_id: u32, border: Border) -> Result<(), S
|
||||
})
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn set_color_calibration(calibration: ColorCalibration) -> Result<(), String> {
|
||||
let config_manager = ambient_light::ConfigManager::global().await;
|
||||
config_manager
|
||||
.set_color_calibration(calibration)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
error!("can not set color calibration: {}", e);
|
||||
e.to_string()
|
||||
})
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
env_logger::init();
|
||||
@ -194,6 +208,7 @@ async fn main() {
|
||||
send_colors,
|
||||
move_strip_part,
|
||||
reverse_led_strip_part,
|
||||
set_color_calibration,
|
||||
])
|
||||
.register_uri_scheme_protocol("ambient-light", move |_app, request| {
|
||||
let response = ResponseBuilder::new().header("Access-Control-Allow-Origin", "*");
|
||||
@ -359,6 +374,7 @@ async fn main() {
|
||||
.unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
let app_handle = app.handle().clone();
|
||||
tokio::spawn(async move {
|
||||
let publisher = ambient_light::LedColorsPublisher::global().await;
|
||||
|
Reference in New Issue
Block a user