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).
147 lines
5.6 KiB
Python
147 lines
5.6 KiB
Python
"""Settings dialog: Discord Rich Presence config + manual update check.
|
|
Both features live here on purpose (not on the main HUD) - they're
|
|
configure-once, not something you watch continuously."""
|
|
from __future__ import annotations
|
|
|
|
from PySide6.QtWidgets import (
|
|
QCheckBox,
|
|
QDialog,
|
|
QFormLayout,
|
|
QGroupBox,
|
|
QHBoxLayout,
|
|
QLabel,
|
|
QLineEdit,
|
|
QPushButton,
|
|
QSpinBox,
|
|
QVBoxLayout,
|
|
)
|
|
|
|
from settings_store import ROTATION_KEYS, ROTATION_LABELS, SettingsStore
|
|
from update_checker import check_for_update
|
|
from version import APP_VERSION
|
|
|
|
|
|
class SettingsDialog(QDialog):
|
|
def __init__(self, settings: SettingsStore, parent=None) -> None:
|
|
super().__init__(parent)
|
|
self.settings = settings
|
|
self.setWindowTitle("Einstellungen")
|
|
self.setMinimumWidth(420)
|
|
|
|
root = QVBoxLayout(self)
|
|
root.setSpacing(14)
|
|
|
|
# -- Discord RPC ---------------------------------------------------
|
|
discord_box = QGroupBox("Discord Rich Presence")
|
|
discord_layout = QVBoxLayout(discord_box)
|
|
|
|
self.discord_enabled_cb = QCheckBox("Discord-Status anzeigen")
|
|
self.discord_enabled_cb.setChecked(settings.discord_enabled)
|
|
discord_layout.addWidget(self.discord_enabled_cb)
|
|
|
|
form = QFormLayout()
|
|
self.client_id_edit = QLineEdit(settings.discord_client_id)
|
|
self.client_id_edit.setPlaceholderText("Discord Application Client ID")
|
|
form.addRow("Client ID:", self.client_id_edit)
|
|
|
|
self.interval_spin = QSpinBox()
|
|
self.interval_spin.setRange(5, 120)
|
|
self.interval_spin.setSuffix(" s")
|
|
self.interval_spin.setValue(settings.discord_rotation_interval_s)
|
|
form.addRow("Wechsel alle:", self.interval_spin)
|
|
discord_layout.addLayout(form)
|
|
|
|
hint = QLabel(
|
|
"Client ID kommt aus dem Discord Developer Portal "
|
|
"(discord.com/developers/applications → deine App → General Information)."
|
|
)
|
|
hint.setProperty("role", "dim")
|
|
hint.setWordWrap(True)
|
|
discord_layout.addWidget(hint)
|
|
|
|
discord_layout.addWidget(QLabel("In der Rotation zeigen:"))
|
|
self.rotation_checkboxes: dict[str, QCheckBox] = {}
|
|
for key in ROTATION_KEYS:
|
|
cb = QCheckBox(ROTATION_LABELS[key])
|
|
cb.setChecked(settings.rotation_enabled(key))
|
|
discord_layout.addWidget(cb)
|
|
self.rotation_checkboxes[key] = cb
|
|
|
|
root.addWidget(discord_box)
|
|
|
|
# -- Updates ---------------------------------------------------------
|
|
update_box = QGroupBox("Updates")
|
|
update_layout = QVBoxLayout(update_box)
|
|
|
|
version_label = QLabel(f"Installierte Version: {APP_VERSION}")
|
|
version_label.setProperty("role", "dim")
|
|
update_layout.addWidget(version_label)
|
|
|
|
url_form = QFormLayout()
|
|
self.manifest_url_edit = QLineEdit(settings.update_manifest_url)
|
|
self.manifest_url_edit.setPlaceholderText("https://.../fhud-version.json")
|
|
url_form.addRow("Update-Quelle:", self.manifest_url_edit)
|
|
update_layout.addLayout(url_form)
|
|
|
|
check_row = QHBoxLayout()
|
|
self.check_button = QPushButton("Auf Updates prüfen")
|
|
self.check_button.setProperty("role", "primary")
|
|
self.check_button.clicked.connect(self._on_check_updates)
|
|
check_row.addWidget(self.check_button)
|
|
check_row.addStretch(1)
|
|
update_layout.addLayout(check_row)
|
|
|
|
self.update_result_label = QLabel("")
|
|
self.update_result_label.setWordWrap(True)
|
|
self.update_result_label.setProperty("role", "dim")
|
|
update_layout.addWidget(self.update_result_label)
|
|
|
|
self.download_button = QPushButton("Download öffnen")
|
|
self.download_button.hide()
|
|
self.download_button.clicked.connect(self._open_download)
|
|
update_layout.addWidget(self.download_button)
|
|
|
|
root.addWidget(update_box)
|
|
|
|
# -- Save/Close --------------------------------------------------------
|
|
button_row = QHBoxLayout()
|
|
button_row.addStretch(1)
|
|
save_btn = QPushButton("Speichern")
|
|
save_btn.setProperty("role", "primary")
|
|
save_btn.clicked.connect(self._save_and_close)
|
|
button_row.addWidget(save_btn)
|
|
root.addLayout(button_row)
|
|
|
|
self._pending_download_url = None
|
|
|
|
def _on_check_updates(self) -> None:
|
|
self.check_button.setEnabled(False)
|
|
self.update_result_label.setText("Prüfe…")
|
|
self.download_button.hide()
|
|
from PySide6.QtWidgets import QApplication
|
|
|
|
QApplication.instance().processEvents()
|
|
|
|
result = check_for_update(self.manifest_url_edit.text().strip())
|
|
self.update_result_label.setText(result.message)
|
|
if result.ok and result.update_available and result.download_url:
|
|
self._pending_download_url = result.download_url
|
|
self.download_button.show()
|
|
self.check_button.setEnabled(True)
|
|
|
|
def _open_download(self) -> None:
|
|
if self._pending_download_url:
|
|
from PySide6.QtGui import QDesktopServices
|
|
from PySide6.QtCore import QUrl
|
|
|
|
QDesktopServices.openUrl(QUrl(self._pending_download_url))
|
|
|
|
def _save_and_close(self) -> None:
|
|
self.settings.discord_enabled = self.discord_enabled_cb.isChecked()
|
|
self.settings.discord_client_id = self.client_id_edit.text()
|
|
self.settings.discord_rotation_interval_s = self.interval_spin.value()
|
|
for key, cb in self.rotation_checkboxes.items():
|
|
self.settings.set_rotation_enabled(key, cb.isChecked())
|
|
self.settings.update_manifest_url = self.manifest_url_edit.text()
|
|
self.accept()
|