Add auxiliary monitor configuration and enhance trigger logic for KVM switching
This commit is contained in:
+30
-6
@@ -18,13 +18,20 @@ SUPPORTED_TARGET_PORTS = {
|
||||
@dataclass(slots=True)
|
||||
class AppConfig:
|
||||
device_port: str = "DP1"
|
||||
auxiliary_monitor_id: str | None = None
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict[str, object]) -> "AppConfig":
|
||||
return cls(device_port=_coerce_port_name(data.get("device_port"), "DP1"))
|
||||
return cls(
|
||||
device_port=_coerce_port_name(data.get("device_port"), "DP1"),
|
||||
auxiliary_monitor_id=_coerce_aux_monitor_id(data.get("auxiliary_monitor_id")),
|
||||
)
|
||||
|
||||
def to_dict(self) -> dict[str, str]:
|
||||
return {"device_port": self.device_port}
|
||||
def to_dict(self) -> dict[str, str | None]:
|
||||
return {
|
||||
"device_port": self.device_port,
|
||||
"auxiliary_monitor_id": self.auxiliary_monitor_id,
|
||||
}
|
||||
|
||||
def validate(self) -> list[str]:
|
||||
errors: list[str] = []
|
||||
@@ -43,7 +50,10 @@ class ConfigStore:
|
||||
|
||||
def get(self) -> AppConfig:
|
||||
with self._lock:
|
||||
return AppConfig(device_port=self._config.device_port)
|
||||
return AppConfig(
|
||||
device_port=self._config.device_port,
|
||||
auxiliary_monitor_id=self._config.auxiliary_monitor_id,
|
||||
)
|
||||
|
||||
def save(self, config: AppConfig) -> AppConfig:
|
||||
errors = config.validate()
|
||||
@@ -55,8 +65,14 @@ class ConfigStore:
|
||||
json.dumps(config.to_dict(), indent=2),
|
||||
encoding="utf-8",
|
||||
)
|
||||
self._config = AppConfig(device_port=config.device_port)
|
||||
return AppConfig(device_port=self._config.device_port)
|
||||
self._config = AppConfig(
|
||||
device_port=config.device_port,
|
||||
auxiliary_monitor_id=config.auxiliary_monitor_id,
|
||||
)
|
||||
return AppConfig(
|
||||
device_port=self._config.device_port,
|
||||
auxiliary_monitor_id=self._config.auxiliary_monitor_id,
|
||||
)
|
||||
|
||||
def _load_from_disk(self) -> AppConfig:
|
||||
if not self.path.exists():
|
||||
@@ -79,3 +95,11 @@ def _coerce_port_name(value: object, default: str) -> str:
|
||||
if normalized in SUPPORTED_TARGET_PORTS:
|
||||
return normalized
|
||||
return default
|
||||
|
||||
|
||||
def _coerce_aux_monitor_id(value: object) -> str | None:
|
||||
if isinstance(value, str):
|
||||
normalized = value.strip()
|
||||
if normalized:
|
||||
return normalized
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user