master
John Lauer v0.9.101: PREVENTION guardian (WS_EX_NOACTIVATE on offenders, cleared on last-guard/bring_to_user/close); quiet_console… 3743b45 2mo ago
"""quiet_console.py — no console window may EVER blip onto the user's screen.

John (2026-08-15): "if you're doing a lot of powershell commands via your bridge
... when you open them, don't make a terminal window come to the foreground and
blip." Root cause: the bridge server runs WITHOUT a console (ab spawns it
CREATE_NO_WINDOW / Start-Process -WindowStyle Hidden), so every CONSOLE child it
launches (powershell.exe, kicad-cli.exe) makes Windows allocate a brand-new
VISIBLE console window — a foreground blip per call. GUI children (kicad.exe,
eeschema, pcbnew) are unaffected by the flag either way.

Fix, centrally: imported ONCE at server boot, this wraps subprocess.Popen (which
subprocess.run/check_output use internally) so CREATE_NO_WINDOW is OR'd into
creationflags by default on Windows. Every current and FUTURE subprocess in the
bridge inherits the fix — no per-call-site discipline required. Explicit
creationflags passed by a caller are preserved (we only OR the bit in).
"""
import subprocess
import sys

if sys.platform == "win32":
    CREATE_NO_WINDOW = 0x08000000
    _orig_init = subprocess.Popen.__init__

    def _quiet_init(self, *args, **kwargs):
        try:
            kwargs["creationflags"] = (kwargs.get("creationflags") or 0) | CREATE_NO_WINDOW
        except Exception:
            pass
        _orig_init(self, *args, **kwargs)

    if getattr(subprocess.Popen.__init__, "__name__", "") != "_quiet_init":
        subprocess.Popen.__init__ = _quiet_init