Spaces:
Running
Running
| from __future__ import annotations | |
| import json | |
| import os | |
| import time | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| UNLOCK_JSON = ROOT / "data" / "session_unlocked.json" | |
| def _boot_id() -> int: | |
| try: | |
| import psutil # type: ignore | |
| return int(psutil.boot_time()) | |
| except Exception: | |
| return int(time.time() // 3600) | |
| def is_activated_for_this_boot() -> bool: | |
| """ | |
| True only if the session unlock marker matches this boot. | |
| Used to hard-block voice output before activation. | |
| """ | |
| try: | |
| if not UNLOCK_JSON.exists(): | |
| return False | |
| data = json.loads(UNLOCK_JSON.read_text(encoding="utf-8")) | |
| if not isinstance(data, dict): | |
| return False | |
| return int(data.get("boot_id", 0) or 0) == _boot_id() | |
| except Exception: | |
| return False | |