diff --git a/src/config/schema/mod.rs b/src/config/schema/mod.rs
index 1030de9a..c42f8f3f 100644
--- a/src/config/schema/mod.rs
+++ b/src/config/schema/mod.rs
@@ -37,7 +37,14 @@ pub struct AppConfig {
}
impl AppConfig {
+ pub fn enforce_invariants(&mut self) {
+ if self.hid.backend != HidBackend::Otg {
+ self.msd.enabled = false;
+ }
+ }
+
pub fn apply_platform_defaults(&mut self) {
crate::platform::defaults::apply(self);
+ self.enforce_invariants();
}
}
diff --git a/src/config/store.rs b/src/config/store.rs
index 1ec7e73b..9d066d46 100644
--- a/src/config/store.rs
+++ b/src/config/store.rs
@@ -27,7 +27,8 @@ impl ConfigStore {
}
pub async fn load(&self) -> Result<()> {
- let config = Self::load_config(&self.pool).await?;
+ let mut config = Self::load_config(&self.pool).await?;
+ config.enforce_invariants();
self.cache.store(Arc::new(config));
Ok(())
}
@@ -73,6 +74,8 @@ impl ConfigStore {
pub async fn set(&self, config: AppConfig) -> Result<()> {
let _guard = self.write_lock.lock().await;
+ let mut config = config;
+ config.enforce_invariants();
Self::save_config_to_db(&self.pool, &config).await?;
self.cache.store(Arc::new(config));
@@ -91,6 +94,7 @@ impl ConfigStore {
let current = self.cache.load();
let mut config = (**current).clone();
f(&mut config);
+ config.enforce_invariants();
Self::save_config_to_db(&self.pool, &config).await?;
diff --git a/src/hid/ch9329.rs b/src/hid/ch9329.rs
index e42fd7bc..25cc781a 100644
--- a/src/hid/ch9329.rs
+++ b/src/hid/ch9329.rs
@@ -15,7 +15,7 @@ use std::sync::{mpsc, Arc};
use std::thread;
use std::time::{Duration, Instant};
use tokio::sync::watch;
-use tracing::{info, trace};
+use tracing::{info, trace, warn};
use super::backend::{HidBackend, HidBackendRuntimeSnapshot};
use super::ch9329_proto::{
@@ -36,6 +36,8 @@ const RECONNECT_DELAY_MS: u64 = 2000;
const INIT_WAIT_MS: u64 = 3000;
+const RECONNECT_COMMAND_POLL_MS: u64 = 100;
+
struct Ch9329RuntimeState {
initialized: AtomicBool,
online: AtomicBool,
@@ -117,15 +119,15 @@ pub struct Ch9329Backend {
baud_rate: u32,
worker_tx: Mutex