Validate hotkeys and support Super alias

This commit is contained in:
Thales Maciel 2026-02-25 11:51:39 -03:00
parent 2cbc1a98b9
commit 3bc473262d
6 changed files with 138 additions and 34 deletions

View file

@ -6,6 +6,7 @@ from pathlib import Path
from typing import Any
from constants import DEFAULT_CONFIG_PATH
from hotkey import split_hotkey
DEFAULT_HOTKEY = "Cmd+m"
@ -73,7 +74,11 @@ def load(path: str | None) -> Config:
if not isinstance(data, dict):
raise ValueError("config must be a JSON object")
cfg = _from_dict(data, cfg)
validate(cfg)
return cfg
validate(cfg)
_write_default_config(p, cfg)
return cfg
@ -81,10 +86,19 @@ def redacted_dict(cfg: Config) -> dict[str, Any]:
return asdict(cfg)
def _write_default_config(path: Path, cfg: Config) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(f"{json.dumps(redacted_dict(cfg), indent=2)}\n", encoding="utf-8")
def validate(cfg: Config) -> None:
hotkey = cfg.daemon.hotkey.strip()
if not hotkey:
raise ValueError("daemon.hotkey cannot be empty")
try:
split_hotkey(hotkey)
except ValueError as exc:
raise ValueError(f"daemon.hotkey is invalid: {exc}") from exc
if isinstance(cfg.recording.input, bool):
raise ValueError("recording.input cannot be boolean")