Skip to content

Commit 98c4301

Browse files
committed
fix: keep background update checks quiet
1 parent c75cd18 commit 98c4301

4 files changed

Lines changed: 56 additions & 42 deletions

File tree

desktop_qt_ui/core/git_update_helpers.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ def git_executable(root: Path) -> str:
3030
return str(portable_git)
3131
return os.environ.get("GIT") or shutil.which("git") or "git"
3232

33+
_GIT_CREATION_FLAGS = subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0
3334

34-
def git_output(
35+
36+
def _run_git(
3537
root: Path,
3638
args: list[str],
3739
*,
38-
timeout: float = 15,
40+
timeout: float,
3941
executable: str | None = None,
40-
) -> str | None:
41-
"""Run a Git read command and return trimmed stdout on success."""
42+
) -> subprocess.CompletedProcess[str] | None:
43+
"""Run Git without creating a console window in the desktop application."""
4244
try:
43-
result = subprocess.run(
45+
return subprocess.run(
4446
[executable or git_executable(root), *args],
4547
cwd=root,
4648
capture_output=True,
@@ -49,10 +51,22 @@ def git_output(
4951
timeout=timeout,
5052
encoding="utf-8",
5153
errors="ignore",
54+
creationflags=_GIT_CREATION_FLAGS,
5255
)
5356
except (OSError, subprocess.SubprocessError):
5457
return None
55-
if result.returncode != 0:
58+
59+
60+
def git_output(
61+
root: Path,
62+
args: list[str],
63+
*,
64+
timeout: float = 15,
65+
executable: str | None = None,
66+
) -> str | None:
67+
"""Run a Git read command and return trimmed stdout on success."""
68+
result = _run_git(root, args, timeout=timeout, executable=executable)
69+
if result is None or result.returncode != 0:
5670
return None
5771
return result.stdout.strip()
5872

@@ -70,20 +84,13 @@ def remote_url(root: Path, *, executable: str | None = None) -> str:
7084

7185
def set_origin_url(root: Path, url: str, *, executable: str | None = None) -> bool:
7286
"""Persist a new origin URL for both the UI and maintenance launcher."""
73-
try:
74-
result = subprocess.run(
75-
[executable or git_executable(root), "remote", "set-url", "origin", url],
76-
cwd=root,
77-
capture_output=True,
78-
text=True,
79-
check=False,
80-
timeout=15,
81-
encoding="utf-8",
82-
errors="ignore",
83-
)
84-
except (OSError, subprocess.SubprocessError):
85-
return False
86-
return result.returncode == 0
87+
result = _run_git(
88+
root,
89+
["remote", "set-url", "origin", url],
90+
timeout=15,
91+
executable=executable,
92+
)
93+
return result is not None and result.returncode == 0
8794

8895

8996
def mirror_index(url: str) -> int:
@@ -132,20 +139,13 @@ def fetch_origin(
132139
executable: str | None = None,
133140
) -> bool:
134141
"""Fetch one origin branch, returning whether the remote ref is current."""
135-
try:
136-
result = subprocess.run(
137-
[executable or git_executable(root), "fetch", "origin", branch],
138-
cwd=root,
139-
capture_output=True,
140-
text=True,
141-
check=False,
142-
timeout=timeout,
143-
encoding="utf-8",
144-
errors="ignore",
145-
)
146-
except (OSError, subprocess.SubprocessError):
147-
return False
148-
return result.returncode == 0
142+
result = _run_git(
143+
root,
144+
["fetch", "origin", branch],
145+
timeout=timeout,
146+
executable=executable,
147+
)
148+
return result is not None and result.returncode == 0
149149

150150

151151
def current_commit(root: Path, *, short: bool = False, executable: str | None = None) -> str:

desktop_qt_ui/services/update_service.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ class UpdateInfo:
3434

3535
@property
3636
def is_update_available(self) -> bool:
37-
versions_are_valid = bool(
38-
_version_parts(self.latest_version) and _version_parts(self.current_version)
39-
)
40-
version_update = versions_are_valid and (
41-
compare_versions(self.latest_version, self.current_version) >= 0
37+
version_update = (
38+
bool(_version_parts(self.latest_version))
39+
and bool(_version_parts(self.current_version))
40+
and compare_versions(self.latest_version, self.current_version) > 0
4241
)
4342
commit_update = self.commits_behind > 0
4443
return version_update or commit_update

desktop_qt_ui/ui/main_page/view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def __init__(self, controller, parent=None):
171171
self.controller.state_manager.current_config_changed.connect(self.update_start_button_text)
172172
QTimer.singleShot(100, self.update_start_button_text) # Set initial text
173173
QTimer.singleShot(100, self._sync_workflow_mode_from_config) # Sync workflow mode dropdown
174-
QTimer.singleShot(1500, self._maybe_auto_check_updates)
174+
QTimer.singleShot(5000, self._maybe_auto_check_updates)
175175

176176
def _create_translation_interface(self, translation_page: QWidget) -> QWidget:
177177
interface = QWidget()

test/test_update_service.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import _bootstrap # noqa: F401, I001
22
import builtins
33
import importlib.util
4+
from desktop_qt_ui.core import git_update_helpers
45
from services import update_service
56
from services.update_service import UpdateInfo, compare_versions
67

@@ -26,12 +27,26 @@ def test_compare_versions_handles_v_prefix_and_missing_patch_parts():
2627
assert compare_versions("2.1.99", "2.2") == -1
2728

2829

29-
def test_update_info_reports_same_or_newer_release_as_available():
30+
def test_git_commands_use_no_window_creation_flags(monkeypatch, tmp_path):
31+
captured = {}
32+
33+
def fake_run(args, **kwargs):
34+
captured.update(kwargs)
35+
return git_update_helpers.subprocess.CompletedProcess(args, 0, "ok\n", "")
36+
37+
monkeypatch.setattr(git_update_helpers.subprocess, "run", fake_run)
38+
monkeypatch.setattr(git_update_helpers, "_GIT_CREATION_FLAGS", 0x08000000)
39+
40+
assert git_update_helpers.git_output(tmp_path, ["status"], executable="git") == "ok"
41+
assert captured["creationflags"] == 0x08000000
42+
43+
44+
def test_update_info_reports_only_newer_release_as_available():
3045
newer = UpdateInfo("2.2.10", "2.2.11", "https://example.test", "", "")
3146
same = UpdateInfo("2.2.10", "2.2.10", "https://example.test", "", "")
3247
unknown = UpdateInfo("unknown", "unknown", "https://example.test", "", "")
3348
assert newer.is_update_available
34-
assert same.is_update_available
49+
assert not same.is_update_available
3550
assert not unknown.is_update_available
3651

3752

0 commit comments

Comments
 (0)