|
11 | 11 | from PySide6.QtUiTools import QUiLoader |
12 | 12 | from PySide6.QtWidgets import QDialog, QFileDialog, QMessageBox |
13 | 13 | from PySide6.QtCore import QFile |
| 14 | + from PySide6.QtGui import QDesktopServices |
| 15 | + from PySide6.QtCore import QUrl |
14 | 16 | from ui.settings import Ui_Dialog |
15 | 17 | from ui.help import Ui_HelpDialog |
16 | 18 | except ImportError: |
17 | 19 | print("PySide6 is not installed. Please install it to use this module.") |
18 | 20 |
|
| 21 | +import json |
| 22 | +try: |
| 23 | + import requests |
| 24 | +except ImportError: |
| 25 | + requests = None |
| 26 | + |
| 27 | +CURRENT_VERSION = "v1.5.1" |
| 28 | + |
19 | 29 | def action_save_as(ui): |
20 | 30 | """ |
21 | 31 | Save the current state of the application as a new file. |
@@ -76,17 +86,17 @@ def clear_buffer(ui): |
76 | 86 |
|
77 | 87 | def show_about_dialog(ui): |
78 | 88 | """ Show the about dialog """ |
79 | | - # Crete a message box to display the about information |
| 89 | + # Create a message box to display the about information |
80 | 90 | msg_box = QMessageBox() |
81 | 91 | msg_box.setWindowTitle("About") |
82 | | - msg_box.setText("AFCOM Client v1.4.0.0 (C) 2020 - 2025 \r\n\r\nAuthor: Mehmet Cagri Aksoy \r\ngithub.com/mcagriaksoy") |
| 92 | + # Use CURRENT_VERSION for the version number |
| 93 | + msg_box.setText(f"AFCOM Client {CURRENT_VERSION} (C) 2020 - 2025 \r\n\r\nAuthor: Mehmet Cagri Aksoy \r\ngithub.com/mcagriaksoy") |
83 | 94 | msg_box.setIcon(QMessageBox.Information) |
84 | 95 | msg_box.setStandardButtons(QMessageBox.Ok) |
85 | 96 | msg_box.setDefaultButton(QMessageBox.Ok) |
86 | 97 | msg_box.setModal(True) |
87 | 98 | msg_box.exec() # Show the message box modally |
88 | 99 |
|
89 | | - |
90 | 100 | def show_help_dialog(ui): |
91 | 101 | """ Show the help dialog """ |
92 | 102 | if PROGRAM_TYPE_DEBUG: |
@@ -146,10 +156,36 @@ def show_settings_dialog(ui): |
146 | 156 | print(f"Error in show_settings_dialog: {e}") |
147 | 157 |
|
148 | 158 | def check_for_updates(ui): |
149 | | - """ Check for updates """ |
150 | | - # Placeholder function for checking updates |
151 | | - # You can implement the actual update check logic here |
152 | | - QMessageBox.information(ui, "Check for Updates", "No updates available at this time.") |
| 159 | + """Check for updates by comparing the latest GitHub tag with the current version.""" |
| 160 | + if requests is None: |
| 161 | + QMessageBox.warning(None, "Check for Updates", "The 'requests' library is not installed. Please install it to check for updates.") |
| 162 | + return |
| 163 | + try: |
| 164 | + url = "https://api.github.com/repos/mcagriaksoy/Serial-Communication-GUI-Program/tags" |
| 165 | + response = requests.get(url, timeout=5) |
| 166 | + if response.status_code == 200: |
| 167 | + tags = response.json() |
| 168 | + if tags: |
| 169 | + latest_tag = tags[0]["name"] |
| 170 | + if latest_tag != CURRENT_VERSION: |
| 171 | + msg_box = QMessageBox() |
| 172 | + msg_box.setWindowTitle("Update Available") |
| 173 | + msg_box.setText(f"A new version is available: {latest_tag}\nYou are using: {CURRENT_VERSION}\nWould you like to download the latest version?") |
| 174 | + download_button = msg_box.addButton("Download", QMessageBox.AcceptRole) |
| 175 | + msg_box.addButton(QMessageBox.Ok) |
| 176 | + msg_box.setIcon(QMessageBox.Information) |
| 177 | + msg_box.setModal(True) |
| 178 | + msg_box.exec() |
| 179 | + if msg_box.clickedButton() == download_button: |
| 180 | + QDesktopServices.openUrl(QUrl(f"https://github.com/mcagriaksoy/Serial-Communication-GUI-Program/releases/tag/{latest_tag}")) |
| 181 | + else: |
| 182 | + QMessageBox.information(None, "Check for Updates", "You are using the latest version.") |
| 183 | + else: |
| 184 | + QMessageBox.information(None, "Check for Updates", "No version tags found on GitHub.") |
| 185 | + else: |
| 186 | + QMessageBox.warning(None, "Check for Updates", f"Failed to fetch updates. Status code: {response.status_code}") |
| 187 | + except Exception as e: |
| 188 | + QMessageBox.critical(None, "Check for Updates", f"Error checking for updates: {e}") |
153 | 189 |
|
154 | 190 |
|
155 | 191 |
|
0 commit comments