feat: 支持 WatchDog

This commit is contained in:
mofeng-git
2026-07-16 20:07:33 +08:00
parent 213359b6c8
commit 50dd419e5a
17 changed files with 1127 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ mod computer_use;
mod hid;
mod otg_network;
mod stream;
mod watchdog;
mod web;
pub use atx::*;
@@ -18,6 +19,7 @@ pub use computer_use::*;
pub use hid::*;
pub use otg_network::*;
pub use stream::*;
pub use watchdog::*;
pub use web::*;
#[typeshare]
@@ -41,6 +43,7 @@ pub struct AppConfig {
pub vnc: VncConfig,
pub rtsp: RtspConfig,
pub redfish: RedfishConfig,
pub watchdog: WatchdogConfig,
}
impl AppConfig {
@@ -57,3 +60,18 @@ impl AppConfig {
self.enforce_invariants();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn missing_watchdog_config_defaults_to_disabled() {
let value = serde_json::to_value(AppConfig::default()).unwrap();
let mut object = value.as_object().unwrap().clone();
object.remove("watchdog");
let config: AppConfig = serde_json::from_value(object.into()).unwrap();
assert!(!config.watchdog.enabled);
}
}

View File

@@ -0,0 +1,9 @@
use serde::{Deserialize, Serialize};
use typeshare::typeshare;
#[typeshare]
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(default)]
pub struct WatchdogConfig {
pub enabled: bool,
}

View File

@@ -154,4 +154,24 @@ mod tests {
assert!(config.initialized);
assert_eq!(config.web.http_port, 9000);
}
#[tokio::test]
async fn failed_watchdog_persistence_does_not_update_cache() {
let dir = tempdir().unwrap();
let db_path = dir.path().join("test.db");
let db = DatabasePool::new(&db_path).await.unwrap();
db.init_schema().await.unwrap();
let store = ConfigStore::new(db.clone_pool()).unwrap();
store.load().await.unwrap();
sqlx::query("DROP TABLE config")
.execute(&db.clone_pool())
.await
.unwrap();
assert!(store
.update(|config| config.watchdog.enabled = true)
.await
.is_err());
assert!(!store.get().watchdog.enabled);
}
}