c51b7b74ed
- Opció marcable «Comprova actualitzacions a l'inici» al menú; persisteix a settings.json i llança la comprovació diferida en obrir la finestra. - Tolerància a repos offline/inalcanzables: low-speed abort + techo dur de temps a les operacions git de xarxa (fetch/clone), evitant cuelgues. - Timeouts exposats a settings.json (git_fetch_timeout, git_clone_timeout, http_timeout, git_stall_limit, git_stall_time) via NetConfig, propagats UI -> workers -> gitops. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
61 lines
2.2 KiB
Python
61 lines
2.2 KiB
Python
"""Preferencias persistentes en settings.json, junto al ejecutable."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from dataclasses import asdict, dataclass, field
|
|
from pathlib import Path
|
|
|
|
from .paths import base_dir
|
|
|
|
SETTINGS_NAME = "settings.json"
|
|
|
|
|
|
@dataclass
|
|
class Settings:
|
|
hide_not_downloaded: bool = False
|
|
updates_pending: list[str] = field(default_factory=list) # ids con update pendiente
|
|
gitea_token: str = "" # token personal de Gitea para repos privados (no se versiona)
|
|
check_updates_on_start: bool = False # comprobar updates automáticamente al iniciar
|
|
# Tolerancia a repos offline/inalcanzables (segundos, salvo stall_limit en bytes/s).
|
|
git_fetch_timeout: int = 60 # techo para fetch / comprobar update
|
|
git_clone_timeout: int = 900 # techo para clone (repo grande)
|
|
http_timeout: int = 15 # techo para la API de Gitea
|
|
git_stall_limit: int = 1000 # bytes/s: por debajo se considera transferencia estancada
|
|
git_stall_time: int = 20 # segundos estancado antes de abortar
|
|
|
|
|
|
def settings_path() -> Path:
|
|
return base_dir() / SETTINGS_NAME
|
|
|
|
|
|
def load_settings() -> Settings:
|
|
path = settings_path()
|
|
if not path.exists():
|
|
return Settings()
|
|
try:
|
|
data = json.loads(path.read_text(encoding="utf-8"))
|
|
except (OSError, json.JSONDecodeError):
|
|
return Settings()
|
|
return Settings(
|
|
hide_not_downloaded=bool(data.get("hide_not_downloaded", False)),
|
|
updates_pending=list(data.get("updates_pending", [])),
|
|
gitea_token=str(data.get("gitea_token", "")),
|
|
check_updates_on_start=bool(data.get("check_updates_on_start", False)),
|
|
git_fetch_timeout=int(data.get("git_fetch_timeout", 60)),
|
|
git_clone_timeout=int(data.get("git_clone_timeout", 900)),
|
|
http_timeout=int(data.get("http_timeout", 15)),
|
|
git_stall_limit=int(data.get("git_stall_limit", 1000)),
|
|
git_stall_time=int(data.get("git_stall_time", 20)),
|
|
)
|
|
|
|
|
|
def save_settings(settings: Settings) -> None:
|
|
try:
|
|
settings_path().write_text(
|
|
json.dumps(asdict(settings), ensure_ascii=False, indent=2),
|
|
encoding="utf-8",
|
|
)
|
|
except OSError:
|
|
pass
|