From 8932199513ccbfc573aeb07558b4053d9fb79a94 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 28 Jul 2025 21:52:18 +1000 Subject: [PATCH] Possible fix for launcher failing to appear on some Linux systems While testing the previous PR, I noticed that if stdout is set to None, the same behaviour is shown as in the following report: https://forums.ankiweb.net/t/cannot-switch-versions/64565 This leads me to wonder whether IsTerminal is behaving differently on that user's system, and the use of an env var may be more reliable. --- qt/aqt/package.py | 1 + qt/launcher/addon/__init__.py | 1 + qt/launcher/src/platform/mod.rs | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/qt/aqt/package.py b/qt/aqt/package.py index a2d8fd4c4..5d349c473 100644 --- a/qt/aqt/package.py +++ b/qt/aqt/package.py @@ -147,6 +147,7 @@ def update_and_restart() -> None: with contextlib.suppress(ResourceWarning): env = os.environ.copy() + env["ANKI_LAUNCHER_WANT_TERMINAL"] = "1" # fixes a bug where launcher fails to appear if opening it # straight after updating if "GNOME_TERMINAL_SCREEN" in env: diff --git a/qt/launcher/addon/__init__.py b/qt/launcher/addon/__init__.py index 5b7ce7fc3..4ef348b9f 100644 --- a/qt/launcher/addon/__init__.py +++ b/qt/launcher/addon/__init__.py @@ -90,6 +90,7 @@ def update_and_restart() -> None: with contextlib.suppress(ResourceWarning): env = os.environ.copy() + env["ANKI_LAUNCHER_WANT_TERMINAL"] = "1" creationflags = 0 if sys.platform == "win32": creationflags = ( diff --git a/qt/launcher/src/platform/mod.rs b/qt/launcher/src/platform/mod.rs index 50a303656..6a582f1aa 100644 --- a/qt/launcher/src/platform/mod.rs +++ b/qt/launcher/src/platform/mod.rs @@ -116,8 +116,9 @@ pub use windows::ensure_terminal_shown; pub fn ensure_terminal_shown() -> Result<()> { use std::io::IsTerminal; + let want_terminal = std::env::var("ANKI_LAUNCHER_WANT_TERMINAL").is_ok(); let stdout_is_terminal = IsTerminal::is_terminal(&std::io::stdout()); - if !stdout_is_terminal { + if want_terminal || !stdout_is_terminal { #[cfg(target_os = "macos")] mac::relaunch_in_terminal()?; #[cfg(not(target_os = "macos"))]