This commit is contained in:
2026-03-23 21:47:25 -07:00
parent 23a73a94e6
commit 96f327e4dc
6 changed files with 166 additions and 81 deletions

View File

@@ -1766,27 +1766,35 @@ def main(argv: Optional[list[str]] = None) -> int:
# Keep trying.
time.sleep(0.10)
command_client = MPVIPCClient(socket_path=str(args.ipc), timeout=0.75, silent=True)
use_shared_ipc_client = platform.system() == "Windows"
command_client = None if use_shared_ipc_client else MPVIPCClient(socket_path=str(args.ipc), timeout=0.75, silent=True)
def _send_helper_command(command: Any, label: str = "") -> bool:
with command_client_lock:
target_client = client if use_shared_ipc_client else command_client
if target_client is None:
return False
try:
if command_client.sock is None:
if not command_client.connect():
if target_client.sock is None:
if use_shared_ipc_client:
if note_ipc_unavailable is not None:
note_ipc_unavailable(f"helper-command-connect:{label or '?'}")
return False
if not target_client.connect():
_append_helper_log(
f"[helper-ipc] connect failed label={label or '?'}"
)
_note_ipc_unavailable(f"helper-command-connect:{label or '?' }")
return False
_mark_ipc_alive(f"helper-command-connect:{label or '?'}")
rid = command_client.send_command_no_wait(command)
rid = target_client.send_command_no_wait(command)
if rid is None:
_append_helper_log(
f"[helper-ipc] send failed label={label or '?'}"
)
_note_ipc_unavailable(f"helper-command-send:{label or '?'}")
try:
command_client.disconnect()
target_client.disconnect()
except Exception:
pass
return False
@@ -1798,7 +1806,7 @@ def main(argv: Optional[list[str]] = None) -> int:
)
_note_ipc_unavailable(f"helper-command-exception:{label or '?'}")
try:
command_client.disconnect()
target_client.disconnect()
except Exception:
pass
return False
@@ -1906,19 +1914,24 @@ def main(argv: Optional[list[str]] = None) -> int:
except Exception:
pass
_start_ready_heartbeat(
str(args.ipc),
stop_event,
_mark_ipc_alive,
_note_ipc_unavailable,
)
_start_request_poll_loop(
str(args.ipc),
stop_event,
_process_request,
_mark_ipc_alive,
_note_ipc_unavailable,
)
if use_shared_ipc_client:
_append_helper_log(
"[helper] Windows single-client IPC mode enabled; auxiliary heartbeat/poll disabled"
)
else:
_start_ready_heartbeat(
str(args.ipc),
stop_event,
_mark_ipc_alive,
_note_ipc_unavailable,
)
_start_request_poll_loop(
str(args.ipc),
stop_event,
_process_request,
_mark_ipc_alive,
_note_ipc_unavailable,
)
# Pre-compute store choices at startup and publish to a cached property so Lua
# can read immediately without waiting for a request/response cycle (which may timeout).
@@ -2075,10 +2088,11 @@ def main(argv: Optional[list[str]] = None) -> int:
_append_helper_log(f"[helper] exiting reason={shutdown_reason}")
except Exception:
pass
try:
command_client.disconnect()
except Exception:
pass
if command_client is not None:
try:
command_client.disconnect()
except Exception:
pass
try:
client.disconnect()
except Exception: