From df4c7d504bec53a1b8f71071b7dbc5b7ed55844c Mon Sep 17 00:00:00 2001 From: DARKZOUL5 Date: Wed, 3 Jun 2026 18:07:11 +0300 Subject: [PATCH] feat: add app version to about page --- .github/workflows/build-release.yml | 10 ++++++-- src/app/core/utils/version.py | 38 +++++++++++++++++++++++++++++ src/app/gui/pages/about.py | 6 +++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/app/core/utils/version.py diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 61a9613..5cb8249 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -107,6 +107,12 @@ jobs: echo "tag=${TAG}" >> "$GITHUB_OUTPUT" echo "version=${TAG#v}" >> "$GITHUB_OUTPUT" + - name: Write bundled version file + shell: bash + run: | + set -euo pipefail + printf '%s\n' "${{ steps.version.outputs.version }}" > version.txt + - uses: actions/setup-python@v6 with: python-version: "3.12" @@ -124,14 +130,14 @@ jobs: run: | $ErrorActionPreference = "Stop" $ws = "${{ github.workspace }}" - pyinstaller --noconfirm --onefile --noconsole --name "ytpl-sync" --icon "$ws/assets/icon.ico" --add-data "$ws/assets/icon.png;assets" --distpath "dist/pyinstaller" --workpath "build/pyinstaller" --specpath "build/pyinstaller" --paths "src" "ytpl-sync-entry.py" + pyinstaller --noconfirm --onefile --noconsole --name "ytpl-sync" --icon "$ws/assets/icon.ico" --add-data "$ws/assets/icon.png;assets" --add-data "$ws/version.txt;." --distpath "dist/pyinstaller" --workpath "build/pyinstaller" --specpath "build/pyinstaller" --paths "src" "ytpl-sync-entry.py" - name: Build binary (Linux) if: runner.os == 'Linux' shell: bash run: | set -euo pipefail - pyinstaller --noconfirm --onefile --noconsole --name "ytpl-sync" --icon "${GITHUB_WORKSPACE}/assets/icon.png" --add-data "${GITHUB_WORKSPACE}/assets/icon.png:assets" --distpath "dist/pyinstaller" --workpath "build/pyinstaller" --specpath "build/pyinstaller" --paths "src" "ytpl-sync-entry.py" + pyinstaller --noconfirm --onefile --noconsole --name "ytpl-sync" --icon "${GITHUB_WORKSPACE}/assets/icon.png" --add-data "${GITHUB_WORKSPACE}/assets/icon.png:assets" --add-data "${GITHUB_WORKSPACE}/version.txt:." --distpath "dist/pyinstaller" --workpath "build/pyinstaller" --specpath "build/pyinstaller" --paths "src" "ytpl-sync-entry.py" - name: Stage package shell: bash diff --git a/src/app/core/utils/version.py b/src/app/core/utils/version.py new file mode 100644 index 0000000..c9f76bf --- /dev/null +++ b/src/app/core/utils/version.py @@ -0,0 +1,38 @@ +from __future__ import annotations + +import sys +from pathlib import Path + + +def _resource_base() -> Path: + # PyInstaller sets sys._MEIPASS to the temp extraction dir. + base = getattr(sys, "_MEIPASS", None) + if base: + return Path(str(base)) + return Path.cwd() + + +def _read_text(path: Path) -> str | None: + try: + if path.exists(): + text = path.read_text(encoding="utf-8").strip() + return text or None + except Exception: + pass + return None +def get_app_version() -> str: + """ + Returns the packaged app version. + + In release builds this reads from `version.txt` bundled into the EXE. + """ + candidates = [ + Path("version.txt"), + _resource_base() / "version.txt", + ] + for candidate in candidates: + text = _read_text(candidate) + if text: + return text + + return "dev" diff --git a/src/app/gui/pages/about.py b/src/app/gui/pages/about.py index 551b815..c96979c 100644 --- a/src/app/gui/pages/about.py +++ b/src/app/gui/pages/about.py @@ -2,6 +2,8 @@ from __future__ import annotations from PySide6 import QtCore, QtGui, QtWidgets +from ...core.utils.version import get_app_version + class AboutPage(QtWidgets.QWidget): def __init__(self, parent: QtWidgets.QWidget | None = None) -> None: @@ -79,6 +81,10 @@ class AboutPage(QtWidgets.QWidget): author = self._muted_label("Dark_Zoul") form.addRow("Author", author) + version_text = get_app_version() + version = self._muted_label(f"v{version_text}" if version_text != "unknown" else version_text) + form.addRow("Version", version) + repo_row = QtWidgets.QHBoxLayout() repo_row.setContentsMargins(0, 0, 0, 0) repo_row.setSpacing(10)