feat: persist audio capture device selection to config.yaml
Device choice now survives server restarts. Falls back to default if the saved device is no longer available.
This commit is contained in:
@@ -451,6 +451,34 @@ class ConfigManager:
|
|||||||
del settings.links[name]
|
del settings.links[name]
|
||||||
logger.info(f"Link '{name}' deleted from config")
|
logger.info(f"Link '{name}' deleted from config")
|
||||||
|
|
||||||
|
def set_setting(self, key: str, value) -> None:
|
||||||
|
"""Set a top-level config setting and persist to YAML.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
key: Setting name (e.g., "visualizer_device").
|
||||||
|
value: Setting value (None removes the key).
|
||||||
|
"""
|
||||||
|
with self._lock:
|
||||||
|
if not self._config_path.exists():
|
||||||
|
data = {}
|
||||||
|
else:
|
||||||
|
with open(self._config_path, "r", encoding="utf-8") as f:
|
||||||
|
data = yaml.safe_load(f) or {}
|
||||||
|
|
||||||
|
if value is None:
|
||||||
|
data.pop(key, None)
|
||||||
|
else:
|
||||||
|
data[key] = value
|
||||||
|
|
||||||
|
self._config_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
with open(self._config_path, "w", encoding="utf-8") as f:
|
||||||
|
yaml.dump(data, f, default_flow_style=False, sort_keys=False)
|
||||||
|
|
||||||
|
# Update in-memory settings
|
||||||
|
if hasattr(settings, key):
|
||||||
|
setattr(settings, key, value)
|
||||||
|
logger.info("Setting '%s' updated to: %s", key, value)
|
||||||
|
|
||||||
|
|
||||||
# Global config manager instance
|
# Global config manager instance
|
||||||
config_manager = ConfigManager()
|
config_manager = ConfigManager()
|
||||||
|
|||||||
@@ -307,6 +307,12 @@ async def set_visualizer_device(
|
|||||||
# set_device() handles stop/start internally if capture was running
|
# set_device() handles stop/start internally if capture was running
|
||||||
success = analyzer.set_device(device_name)
|
success = analyzer.set_device(device_name)
|
||||||
|
|
||||||
|
# Persist selection to config.yaml so it survives server restarts
|
||||||
|
if success:
|
||||||
|
from ..config_manager import config_manager
|
||||||
|
|
||||||
|
config_manager.set_setting("visualizer_device", device_name)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"success": success,
|
"success": success,
|
||||||
"current_device": analyzer.current_device,
|
"current_device": analyzer.current_device,
|
||||||
|
|||||||
Reference in New Issue
Block a user