mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-19 09:48:12 +00:00
Add check for available software updates (#118)
* Add feature to check github repo for available updates * Add Check for Updates to Help menu
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
''' app/ui/widgets/menubar.py '''
|
||||
import sys
|
||||
|
||||
from PyQt6.QtGui import QAction
|
||||
from PyQt6.QtWidgets import QMenuBar, QApplication
|
||||
from PyQt6.QtWidgets import QMenuBar, QApplication, QMessageBox, QDialog, QVBoxLayout, QLabel, QPushButton
|
||||
|
||||
|
||||
class MenuBar(QMenuBar):
|
||||
@@ -43,6 +41,9 @@ class MenuBar(QMenuBar):
|
||||
about_action = QAction("About", self)
|
||||
about_action.triggered.connect(self.show_about)
|
||||
help_menu.addAction(about_action)
|
||||
update_action = QAction("Check for Updates...", self)
|
||||
update_action.triggered.connect(self.check_for_updates)
|
||||
help_menu.addAction(update_action)
|
||||
|
||||
def new_job(self):
|
||||
self.parent().new_job()
|
||||
@@ -55,3 +56,46 @@ class MenuBar(QMenuBar):
|
||||
from src.ui.about_window import AboutDialog
|
||||
dialog = AboutDialog()
|
||||
dialog.exec()
|
||||
|
||||
@staticmethod
|
||||
def check_for_updates():
|
||||
from src.utilities.misc_helper import check_for_updates
|
||||
from version import APP_NAME, APP_VERSION, APP_REPO_NAME, APP_REPO_OWNER
|
||||
found_update = check_for_updates(APP_REPO_NAME, APP_REPO_OWNER, APP_NAME, APP_VERSION)
|
||||
if found_update:
|
||||
dialog = UpdateDialog(found_update, APP_VERSION)
|
||||
dialog.exec()
|
||||
else:
|
||||
QMessageBox.information(None, "No Update", "No updates available.")
|
||||
|
||||
|
||||
class UpdateDialog(QDialog):
|
||||
def __init__(self, release_info, current_version, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setWindowTitle(f"Update Available ({current_version} -> {release_info['tag_name']})")
|
||||
|
||||
layout = QVBoxLayout()
|
||||
label = QLabel(f"A new version ({release_info['tag_name']}) is available! Current version: {current_version}")
|
||||
layout.addWidget(label)
|
||||
|
||||
# Label to show the release notes
|
||||
description = QLabel(release_info["body"])
|
||||
layout.addWidget(description)
|
||||
|
||||
# Button to download the latest version
|
||||
download_button = QPushButton(f"Download Latest Version ({release_info['tag_name']})")
|
||||
download_button.clicked.connect(lambda: self.open_url(release_info["html_url"]))
|
||||
layout.addWidget(download_button)
|
||||
|
||||
# OK button to dismiss the dialog
|
||||
ok_button = QPushButton("Dismiss")
|
||||
ok_button.clicked.connect(self.accept) # Close the dialog when clicked
|
||||
layout.addWidget(ok_button)
|
||||
|
||||
self.setLayout(layout)
|
||||
|
||||
def open_url(self, url):
|
||||
from PyQt6.QtCore import QUrl
|
||||
from PyQt6.QtGui import QDesktopServices
|
||||
QDesktopServices.openUrl(QUrl(url))
|
||||
self.accept()
|
||||
|
||||
Reference in New Issue
Block a user