-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathriot_process.py
More file actions
64 lines (52 loc) · 1.95 KB
/
Copy pathriot_process.py
File metadata and controls
64 lines (52 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from __future__ import annotations
import subprocess
import time
from pathlib import Path
import win32gui
from riot_ui_login import RiotUIError
RIOT_PROCESSES = [
"RiotClientServices.exe",
"RiotClientUx.exe",
"RiotClientUxRender.exe",
"LeagueClient.exe",
"LeagueClientUx.exe",
]
_LOGIN_FORM_MIN_WIDTH = 900
_POLL_INTERVAL = 0.5
_POLL_TIMEOUT = 45.0
_STABLE_POLLS = 4 # consecutive polls at full size before we consider it stable (~2s)
_FORM_LOAD_WAIT = 4.0 # extra seconds after stable for the login form to render inside Electron
def kill_riot_processes() -> None:
for name in RIOT_PROCESSES:
subprocess.run(["taskkill", "/F", "/IM", name], capture_output=True)
time.sleep(1)
def launch_riot_client(exe_path: str) -> None:
if not Path(exe_path).exists():
raise FileNotFoundError(f"Riot Client not found at: {exe_path}")
subprocess.Popen([exe_path])
def wait_for_login_window(timeout: float = _POLL_TIMEOUT) -> int:
"""Poll until Riot Client shows the full-size login form (not the splash).
The Electron window briefly appears at full size while still loading — we
wait for it to stay at full size for several consecutive polls, then add
extra time for the login form to finish rendering inside the web view.
"""
deadline = time.monotonic() + timeout
stable = 0
while time.monotonic() < deadline:
hwnd = win32gui.FindWindow(None, "Riot Client")
if hwnd:
l, t, r, b = win32gui.GetWindowRect(hwnd)
if (r - l) >= _LOGIN_FORM_MIN_WIDTH:
stable += 1
if stable >= _STABLE_POLLS:
time.sleep(_FORM_LOAD_WAIT)
return hwnd
else:
stable = 0
else:
stable = 0
time.sleep(_POLL_INTERVAL)
raise RiotUIError(
"Timed out waiting for Riot Client login window. "
"Make sure the Riot Client opened correctly."
)