d
This commit is contained in:
@@ -33,6 +33,33 @@ _LYRIC_LOG_FH: Optional[Any] = None
|
||||
_MPV_AVAILABILITY_CACHE: Optional[Tuple[bool, Optional[str]]] = None
|
||||
|
||||
|
||||
def _windows_hidden_subprocess_kwargs() -> Dict[str, Any]:
|
||||
"""Best-effort kwargs to avoid flashing console windows on Windows.
|
||||
|
||||
Applies to subprocess.run/check_output/Popen.
|
||||
"""
|
||||
if platform.system() != "Windows":
|
||||
return {}
|
||||
|
||||
kwargs: Dict[str, Any] = {}
|
||||
try:
|
||||
create_no_window = getattr(subprocess, "CREATE_NO_WINDOW", 0x08000000)
|
||||
kwargs["creationflags"] = int(create_no_window)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Also set startupinfo to hidden, for APIs that honor it.
|
||||
try:
|
||||
si = subprocess.STARTUPINFO()
|
||||
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||
si.wShowWindow = subprocess.SW_HIDE
|
||||
kwargs["startupinfo"] = si
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return kwargs
|
||||
|
||||
|
||||
def _check_mpv_availability() -> Tuple[bool, Optional[str]]:
|
||||
"""Return (available, reason) for the mpv executable.
|
||||
|
||||
@@ -57,6 +84,7 @@ def _check_mpv_availability() -> Tuple[bool, Optional[str]]:
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=2,
|
||||
**_windows_hidden_subprocess_kwargs(),
|
||||
)
|
||||
if result.returncode == 0:
|
||||
_MPV_AVAILABILITY_CACHE = (True, None)
|
||||
@@ -97,6 +125,7 @@ def _windows_list_lyric_helper_pids(ipc_path: str) -> List[int]:
|
||||
stderr=subprocess.DEVNULL,
|
||||
timeout=2,
|
||||
text=True,
|
||||
**_windows_hidden_subprocess_kwargs(),
|
||||
)
|
||||
except Exception:
|
||||
return []
|
||||
@@ -141,6 +170,7 @@ def _windows_kill_pids(pids: List[int]) -> None:
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
timeout=2,
|
||||
**_windows_hidden_subprocess_kwargs(),
|
||||
)
|
||||
except Exception:
|
||||
continue
|
||||
@@ -384,6 +414,7 @@ class MPV:
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
timeout=2,
|
||||
**_windows_hidden_subprocess_kwargs(),
|
||||
)
|
||||
except Exception:
|
||||
return
|
||||
@@ -415,8 +446,20 @@ class MPV:
|
||||
cmd.extend([str(a) for a in extra_args if a])
|
||||
|
||||
kwargs: Dict[str, Any] = {}
|
||||
if detached and platform.system() == "Windows":
|
||||
kwargs["creationflags"] = 0x00000008 # DETACHED_PROCESS
|
||||
if platform.system() == "Windows":
|
||||
# Ensure we don't flash a console window when spawning mpv.
|
||||
flags = 0
|
||||
try:
|
||||
flags |= int(getattr(subprocess, "DETACHED_PROCESS", 0x00000008)) if detached else 0
|
||||
except Exception:
|
||||
flags |= 0x00000008 if detached else 0
|
||||
try:
|
||||
flags |= int(getattr(subprocess, "CREATE_NO_WINDOW", 0x08000000))
|
||||
except Exception:
|
||||
flags |= 0x08000000
|
||||
kwargs["creationflags"] = flags
|
||||
# startupinfo is harmless for GUI apps; helps hide flashes for console-subsystem builds.
|
||||
kwargs.update({k: v for k, v in _windows_hidden_subprocess_kwargs().items() if k != "creationflags"})
|
||||
|
||||
debug("Starting MPV")
|
||||
subprocess.Popen(cmd, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user