This commit is contained in:
2026-02-03 17:14:11 -08:00
parent 1e0000ae19
commit cc19403087
6 changed files with 279 additions and 51 deletions

View File

@@ -7,6 +7,7 @@ This is the central hub for all Python-mpv IPC communication. The Lua script
should use the Python CLI, which uses this module to manage mpv connections.
"""
import ctypes
import json
import os
import platform
@@ -30,6 +31,23 @@ _LYRIC_LOG_FH: Optional[Any] = None
_MPV_AVAILABILITY_CACHE: Optional[Tuple[bool, Optional[str]]] = None
def _windows_pipe_available(path: str) -> bool:
"""Check if a Windows named pipe is ready without raising."""
if platform.system() != "Windows":
return False
if not path:
return False
try:
kernel32 = ctypes.windll.kernel32
WaitNamedPipeW = kernel32.WaitNamedPipeW
WaitNamedPipeW.argtypes = [ctypes.c_wchar_p, ctypes.c_uint32]
WaitNamedPipeW.restype = ctypes.c_bool
# Timeout 0 ensures we don't block.
return bool(WaitNamedPipeW(path, 0))
except Exception:
return False
def _windows_pythonw_exe(python_exe: Optional[str]) -> Optional[str]:
"""Return a pythonw.exe adjacent to python.exe if available (Windows only)."""
if platform.system() != "Windows":
@@ -970,6 +988,11 @@ class MPVIPCClient:
try:
if self.is_windows:
# Windows named pipes
if not _windows_pipe_available(self.socket_path):
if not self.silent:
debug("Named pipe not available yet: %s" % self.socket_path)
return False
try:
# Try to open the named pipe
self.sock = open(self.socket_path, "r+b", buffering=0)