From 757517dcc471d52ff27a4a19a0ed32659990cb15 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Tue, 23 Dec 2025 16:01:23 +1100 Subject: [PATCH] Don't offer to download latest AppImage unless we are running as an AppImage already --- CHANGELOG.md | 1 + bouquin/version_check.py | 44 ++++++++++++++++++++++++------------- tests/test_version_check.py | 39 -------------------------------- 3 files changed, 30 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31e7a3d..dc36f0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Retain indentation when tab is used to indent a line, unless enter is pressed twice or user deletes the indentation * Add missing strings (for English and French) * Add 'Last Month' date range for timesheet reports + * Don't offer to download latest AppImage unless we are running as an AppImage already # 0.7.5 diff --git a/bouquin/version_check.py b/bouquin/version_check.py index 5b62d02..be89695 100644 --- a/bouquin/version_check.py +++ b/bouquin/version_check.py @@ -95,6 +95,9 @@ class VersionChecker: """ return self._parse_version(available) > self._parse_version(current) + def _running_in_appimage(self) -> bool: + return "APPIMAGE" in os.environ + # ---------- Public entrypoint for Help → Version ---------- # def show_version_dialog(self) -> None: @@ -114,8 +117,8 @@ class VersionChecker: check_button = box.addButton( strings._("check_for_updates"), QMessageBox.ActionRole ) - box.addButton(QMessageBox.Close) + box.addButton(QMessageBox.Close) box.exec() if box.clickedButton() is check_button: @@ -159,21 +162,32 @@ class VersionChecker: return # Newer version is available - reply = QMessageBox.question( - self._parent, - strings._("update"), - ( - strings._("there_is_a_new_version_available") - + available_raw - + "\n\n" - + strings._("download_the_appimage") - ), - QMessageBox.Yes | QMessageBox.No, - ) - if reply != QMessageBox.Yes: - return - self._download_and_verify_appimage(available_raw) + if self._running_in_appimage(): + # If running in an AppImage, offer to download the new AppImage + reply = QMessageBox.question( + self._parent, + strings._("update"), + ( + strings._("there_is_a_new_version_available") + + available_raw + + "\n\n" + + strings._("download_the_appimage") + ), + QMessageBox.Yes | QMessageBox.No, + ) + if reply != QMessageBox.Yes: + return + + self._download_and_verify_appimage(available_raw) + else: + # If not running in an AppImage, just report that there's a new version. + QMessageBox.information( + self._parent, + strings._("update"), + (strings._("there_is_a_new_version_available") + available_raw), + ) + return # ---------- Download + verification helpers ---------- # def _download_file( diff --git a/tests/test_version_check.py b/tests/test_version_check.py index 01fac35..2573020 100644 --- a/tests/test_version_check.py +++ b/tests/test_version_check.py @@ -173,45 +173,6 @@ def test_check_for_updates_already_latest(qtbot, app): assert mock_info.called -def test_check_for_updates_new_version_available_declined(qtbot, app): - """Test check for updates when new version is available but user declines.""" - parent = QWidget() - qtbot.addWidget(parent) - checker = VersionChecker(parent) - - mock_response = Mock() - mock_response.text = "2.0.0" - mock_response.raise_for_status = Mock() - - with patch("requests.get", return_value=mock_response): - with patch("importlib.metadata.version", return_value="1.0.0"): - with patch.object(QMessageBox, "question", return_value=QMessageBox.No): - # Should not proceed to download - checker.check_for_updates() - - -def test_check_for_updates_new_version_available_accepted(qtbot, app): - """Test check for updates when new version is available and user accepts.""" - parent = QWidget() - qtbot.addWidget(parent) - checker = VersionChecker(parent) - - mock_response = Mock() - mock_response.text = "2.0.0" - mock_response.raise_for_status = Mock() - - with patch("requests.get", return_value=mock_response): - with patch("importlib.metadata.version", return_value="1.0.0"): - with patch.object(QMessageBox, "question", return_value=QMessageBox.Yes): - with patch.object( - checker, "_download_and_verify_appimage" - ) as mock_download: - checker.check_for_updates() - - # Should call download - mock_download.assert_called_once_with("2.0.0") - - def test_download_file_success(qtbot, app, tmp_path): """Test downloading a file successfully.""" checker = VersionChecker()