mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-07-29 11:51:44 +08:00
feat: 初步增加 Windows 支持
This commit is contained in:
@@ -25,6 +25,7 @@ pub async fn update_atx_config(
|
||||
let _apply_guard = try_apply_lock(&state.config_apply_locks.atx, "atx")?;
|
||||
let mut merged_atx_config = old_atx_config.clone();
|
||||
req.apply_to(&mut merged_atx_config);
|
||||
validate_windows_atx_backends(&merged_atx_config)?;
|
||||
validate_serial_device_conflict(&merged_atx_config, ¤t_config.hid)?;
|
||||
|
||||
state
|
||||
@@ -41,6 +42,23 @@ pub async fn update_atx_config(
|
||||
Ok(Json(new_atx_config))
|
||||
}
|
||||
|
||||
fn validate_windows_atx_backends(atx: &AtxConfig) -> Result<()> {
|
||||
if !cfg!(windows) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
for (name, key) in [("power", &atx.power), ("reset", &atx.reset)] {
|
||||
if !matches!(key.driver, AtxDriverType::Serial | AtxDriverType::None) {
|
||||
return Err(AppError::BadRequest(format!(
|
||||
"Windows ATX {} only supports serial relay or none",
|
||||
name
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_serial_device_conflict(atx: &AtxConfig, hid: &HidConfig) -> Result<()> {
|
||||
if hid.backend != HidBackend::Ch9329 {
|
||||
return Ok(());
|
||||
@@ -91,4 +109,13 @@ mod tests {
|
||||
|
||||
assert!(validate_serial_device_conflict(&atx, &hid).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_validate_windows_atx_backends_allows_serial() {
|
||||
let mut atx = AtxConfig::default();
|
||||
atx.power.driver = AtxDriverType::Serial;
|
||||
atx.reset.driver = AtxDriverType::None;
|
||||
|
||||
assert!(validate_windows_atx_backends(&atx).is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user