Initial commit: the FS25 Lua mod (live.json data export), the FS25-WebDashboard project (Node/web dashboard + PySide6 desktop variant), and FarmHUD (standalone PySide6 companion app with Discord Rich Presence, settings, and installer).
65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
"""Manual "check for updates" support (Settings page button).
|
|
|
|
Expects a small JSON manifest at a URL the user configures in Settings:
|
|
|
|
{ "version": "1.2.0", "url": "https://.../FarmHUD-Setup-1.2.0.exe", "notes": "..." }
|
|
|
|
See fhud-version.example.json in the project root for the exact shape.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Optional
|
|
|
|
import requests
|
|
|
|
from version import APP_VERSION
|
|
|
|
|
|
@dataclass
|
|
class UpdateResult:
|
|
ok: bool
|
|
message: str
|
|
update_available: bool = False
|
|
latest_version: Optional[str] = None
|
|
download_url: Optional[str] = None
|
|
notes: Optional[str] = None
|
|
|
|
|
|
def _parse_version(text: str) -> tuple:
|
|
parts = []
|
|
for chunk in text.strip().split("."):
|
|
digits = "".join(c for c in chunk if c.isdigit())
|
|
parts.append(int(digits) if digits else 0)
|
|
return tuple(parts)
|
|
|
|
|
|
def check_for_update(manifest_url: str, timeout_s: float = 6.0) -> UpdateResult:
|
|
if not manifest_url:
|
|
return UpdateResult(ok=False, message="Keine Update-Quelle konfiguriert (siehe Einstellungen).")
|
|
|
|
try:
|
|
resp = requests.get(manifest_url, timeout=timeout_s)
|
|
resp.raise_for_status()
|
|
data = resp.json()
|
|
except requests.RequestException as exc:
|
|
return UpdateResult(ok=False, message=f"Update-Prüfung fehlgeschlagen: {exc}")
|
|
except ValueError:
|
|
return UpdateResult(ok=False, message="Update-Quelle lieferte kein gültiges JSON.")
|
|
|
|
latest = data.get("version")
|
|
if not latest:
|
|
return UpdateResult(ok=False, message="Update-Quelle enthält kein 'version'-Feld.")
|
|
|
|
is_newer = _parse_version(latest) > _parse_version(APP_VERSION)
|
|
if is_newer:
|
|
return UpdateResult(
|
|
ok=True,
|
|
message=f"Neue Version verfügbar: {latest} (aktuell installiert: {APP_VERSION}).",
|
|
update_available=True,
|
|
latest_version=latest,
|
|
download_url=data.get("url"),
|
|
notes=data.get("notes"),
|
|
)
|
|
return UpdateResult(ok=True, message=f"Du bist auf dem neuesten Stand ({APP_VERSION}).", update_available=False)
|