fix windows desktop bridge startup (#1196)
This commit is contained in:
@@ -71,6 +71,40 @@ def _hidden_subprocess_kwargs() -> dict[str, int]:
|
||||
return {"creationflags": getattr(subprocess, "CREATE_NO_WINDOW", 0)}
|
||||
|
||||
|
||||
def _install_windows_hidden_subprocess_defaults() -> None:
|
||||
"""Hide console windows for subprocesses launched inside desktop bridge runs.
|
||||
|
||||
The desktop bridge itself must keep stdout/stderr pipes for readiness and
|
||||
worker handshakes, so it runs under python.exe. On Windows that means any
|
||||
nested console executable, including git.exe from context expansion, can
|
||||
flash a window unless the child process is created with CREATE_NO_WINDOW.
|
||||
"""
|
||||
if os.name != "nt":
|
||||
return
|
||||
if os.environ.get("HERMES_DESKTOP", "").strip().lower() != "true":
|
||||
return
|
||||
if getattr(subprocess, "_hermes_hidden_defaults_installed", False):
|
||||
return
|
||||
|
||||
original_popen = subprocess.Popen
|
||||
create_no_window = getattr(subprocess, "CREATE_NO_WINDOW", 0) or 0x08000000
|
||||
|
||||
class HiddenPopen(original_popen): # type: ignore[misc, valid-type]
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
flags = kwargs.get("creationflags", 0) or 0
|
||||
try:
|
||||
kwargs["creationflags"] = int(flags) | create_no_window
|
||||
except Exception:
|
||||
kwargs["creationflags"] = create_no_window
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
subprocess.Popen = HiddenPopen # type: ignore[assignment]
|
||||
subprocess._hermes_hidden_defaults_installed = True # type: ignore[attr-defined]
|
||||
|
||||
|
||||
_install_windows_hidden_subprocess_defaults()
|
||||
|
||||
|
||||
def _process_exists(pid: int) -> bool:
|
||||
if pid <= 0:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user