Skip to content

Commit

Permalink
refactor github update checker and label to accommodate prerelease
Browse files Browse the repository at this point in the history
  • Loading branch information
cbusillo committed Jun 12, 2024
1 parent 90b9981 commit 7d16cad
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/briefcase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: |
git fetch --tags
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || git rev-list --max-parents=0 HEAD)
MESSAGES=$(git log --no-merges --pretty=format:"- [%h](https://github.com/${{ github.repository }}/commit/%H) %s" "$LAST_TAG"..HEAD | awk '!seen[$NF]++' | grep -v "Bump version")
MESSAGES=$(git log --no-merges --pretty=format:"- [%h](https://github.com/${{ github.repository }}/commit/%H) %s" "$LAST_TAG"..HEAD | grep -v "Bump version")
echo "messages<<EOF" >> $GITHUB_OUTPUT
echo "messages" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
Expand Down
82 changes: 59 additions & 23 deletions bd_to_avp/gui/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
from urllib.parse import urlparse

from PySide6.QtCore import QCoreApplication, Qt
from PySide6.QtWidgets import QApplication, QDialog, QHBoxLayout, QLabel, QPushButton, QVBoxLayout
from github import Github, GithubException
from PySide6.QtWidgets import QApplication, QCheckBox, QDialog, QHBoxLayout, QLabel, QPushButton, QVBoxLayout
from github import Github, GithubException, UnknownObjectException
from github.GitRelease import GitRelease


# noinspection PyAttributeOutsideInit
class AboutDialog(QDialog):
app: QApplication

Expand All @@ -18,6 +20,8 @@ def __init__(self, parent=None) -> None:
raise ValueError("QApplication instance not found.")

self.app = app
self.readme_url = self.app.property("url")
self.repo_name = urlparse(self.readme_url).path.lstrip("/")

self.setWindowTitle(f"About {self.app.applicationDisplayName()}")
self.create_dialog()
Expand All @@ -31,7 +35,7 @@ def create_dialog(self) -> None:
self.add_company_label(layout)
self.add_authors_label(layout)
self.add_readme_label(layout)
self.add_update_label(layout)
self.add_update_section(layout)
self.add_description_label(layout)
self.add_close_button(layout)

Expand Down Expand Up @@ -79,44 +83,76 @@ def add_authors_label(self, layout: QVBoxLayout) -> None:
layout.addWidget(authors_label)

def add_readme_label(self, layout: QVBoxLayout) -> None:
readme_url = self.app.property("url")
if not readme_url:

if not self.readme_url:
return

readme_label = QLabel(f"<a href='{readme_url}'>Readme</a>")
readme_label = QLabel(f"<a href='{self.readme_url}'>Readme</a>")
readme_label.setTextFormat(Qt.TextFormat.RichText)
readme_label.setOpenExternalLinks(True)
readme_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
layout.addWidget(readme_label)

def add_update_label(self, layout: QVBoxLayout) -> None:
readme_url = self.app.property("url")
if not readme_url:
return
def add_update_section(self, layout: QVBoxLayout) -> None:
self.update_label = QLabel()
self.prerelease_checkbox = QCheckBox("Include pre-releases")
self.prerelease_checkbox.stateChanged.connect(self.update_github_update_label)

if self.is_pre_release() or self.is_pre_release() is None:
self.prerelease_checkbox.setChecked(True)

self.update_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.update_label.setTextFormat(Qt.TextFormat.RichText)
self.update_label.setOpenExternalLinks(True)

checkbox_layout = QHBoxLayout()
checkbox_layout.addStretch(1)
checkbox_layout.addWidget(self.prerelease_checkbox)
checkbox_layout.addStretch(1)

layout.addLayout(checkbox_layout)
layout.addWidget(self.update_label)

update_label = QLabel()
update_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
update_label.setTextFormat(Qt.TextFormat.RichText)
update_label.setOpenExternalLinks(True)
self.update_github_update_label()

def update_github_update_label(self) -> None:
try:
github = Github()
repo_name = urlparse(readme_url).path.lstrip("/")
repo = github.get_repo(repo_name)
releases = repo.get_releases()
latest_release = releases[0]
latest_release = self.fetch_latest_release()

if not latest_release:
self.update_label.setText("No releases found.")
return

latest_release_version = latest_release.tag_name.lstrip("v")
latest_release_url = latest_release.html_url
if latest_release_version != self.app.applicationVersion():
update_label.setText(
self.update_label.setText(
f"New version available: <a href='{latest_release_url}'>v{latest_release_version}</a>"
)

else:
update_label.setText(f"You are using the latest <a href='{latest_release_url}'>version</a>.")
self.update_label.setText(f"You are using the latest <a href='{latest_release_url}'>version</a>.")
except GithubException:
update_label.setText("Failed to check for updates.")
self.update_label.setText("Failed to check for updates.")

def fetch_latest_release(self) -> GitRelease | None:
repo = Github().get_repo(self.repo_name)
releases = repo.get_releases()
for release in releases:
if not release.prerelease or self.prerelease_checkbox.isChecked():
return release
return None

def is_pre_release(self) -> bool | None:
repo = Github().get_repo(self.repo_name)
try:
current_release = repo.get_release(f"v{self.app.applicationVersion()}")
except UnknownObjectException:
return None

layout.addWidget(update_label)
if current_release.prerelease:
return True
return False

def add_description_label(self, layout: QVBoxLayout) -> None:
description_label = QLabel(self.get_description_from_readme())
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "bd_to_avp"
version = "0.2.64"
version = "0.2.65"
description = "Script to convert 3D Blu-ray Discs (and mts) to Apple Vision Pro (MV-HEVC) files"
authors = ["Chris Busillo <info@shinycomputers.com>"]
readme = "README.md"
Expand Down Expand Up @@ -40,7 +40,7 @@ build-backend = "poetry.core.masonry.api"
project_name = "3D Blu-ray to Vision pro"
bundle = "com.shinycomputers"
architectures = ["arm64"]
version = "0.2.64"
version = "0.2.65"
icon = "bd_to_avp/resources/app_icon"
organization = "Shiny Computers"

Expand Down

0 comments on commit 7d16cad

Please sign in to comment.