mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-06-17 13:01:45 +08:00
feat: 新增 Linux 绝对鼠标兼容模式 #266;新增 CH9329 描述符设置
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use axum::{extract::State, Json};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::config::HidConfig;
|
||||
use crate::config::{HidBackend, HidConfig};
|
||||
use crate::error::Result;
|
||||
use crate::state::AppState;
|
||||
|
||||
@@ -21,10 +21,20 @@ pub async fn update_hid_config(
|
||||
let _apply_guard = try_apply_lock(&state.config_apply_locks.otg, "otg")?;
|
||||
let old_hid_config = state.config.get().hid.clone();
|
||||
|
||||
let mut staged_hid_config = old_hid_config.clone();
|
||||
req.apply_to(&mut staged_hid_config);
|
||||
let descriptor_update = req
|
||||
.ch9329_descriptor
|
||||
.as_ref()
|
||||
.map(|_| staged_hid_config.ch9329_descriptor.clone());
|
||||
if descriptor_update.is_some() {
|
||||
staged_hid_config.ch9329_descriptor = old_hid_config.ch9329_descriptor.clone();
|
||||
}
|
||||
|
||||
state
|
||||
.config
|
||||
.update(|config| {
|
||||
req.apply_to(&mut config.hid);
|
||||
config.hid = staged_hid_config.clone();
|
||||
config.enforce_invariants();
|
||||
})
|
||||
.await?;
|
||||
@@ -39,5 +49,21 @@ pub async fn update_hid_config(
|
||||
)
|
||||
.await?;
|
||||
|
||||
if let Some(descriptor) = descriptor_update {
|
||||
if new_hid_config.backend != HidBackend::Ch9329 {
|
||||
return Ok(Json(new_hid_config));
|
||||
}
|
||||
|
||||
let actual = state.hid.apply_ch9329_descriptor(&descriptor).await?;
|
||||
state
|
||||
.config
|
||||
.update(|config| {
|
||||
config.hid.ch9329_descriptor = actual.descriptor.clone();
|
||||
config.enforce_invariants();
|
||||
})
|
||||
.await?;
|
||||
return Ok(Json(state.config.get().hid.clone()));
|
||||
}
|
||||
|
||||
Ok(Json(new_hid_config))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user