Dotfiles/desktopenvs/hyprdrive/beacon/config.py

46 lines
1.1 KiB
Python

"""Tiny user-editable config file: ~/.local/state/beacon/config.json.
Read once at startup (main.py, via server.py); a change takes effect on the
next beacon-start.sh restart, not live. Same pattern as orbit-menu/horizon-
dock/astro-menu/station-bar's config.py.
"""
from __future__ import annotations
import json
from paths import CONFIG_FILE, ensure_dirs
_DEFAULTS = {
"history_enabled": True,
"history_length": 100,
"history_persist": True,
}
def _load() -> dict:
try:
data = json.loads(CONFIG_FILE.read_text())
except (FileNotFoundError, json.JSONDecodeError):
data = {}
merged = {**_DEFAULTS, **data}
if not CONFIG_FILE.exists():
ensure_dirs()
CONFIG_FILE.write_text(json.dumps(merged, indent=2) + "\n")
return merged
def history_enabled() -> bool:
return bool(_load().get("history_enabled", True))
def history_length() -> int:
try:
return int(_load().get("history_length", 100))
except (TypeError, ValueError):
return 100
def history_persist() -> bool:
return bool(_load().get("history_persist", True))