mirror of
https://github.com/moraroy/NonSteamLaunchers-On-Steam-Deck.git
synced 2026-06-13 04:04:59 +03:00
Merge pull request #932 from superness/main
fix: retry WebSocket connection on first run instead of silent exit (#895)
This commit is contained in:
+38
-8
@@ -1835,23 +1835,53 @@ THEMEMUSIC_CODE = r"""(function () {
|
||||
|
||||
|
||||
|
||||
# Utility: Fetch debugger targets
|
||||
def fetch_targets(host, port):
|
||||
# Utility: Fetch debugger targets with retry
|
||||
def fetch_targets(host, port, max_retries=15, base_delay=2):
|
||||
"""Fetch debugger targets from Steam CEF debugger, with retry logic.
|
||||
|
||||
Steam's CEF debugger on port 8080 may not be listening on first run.
|
||||
Retries with exponential backoff (capped at 10s) up to max_retries times.
|
||||
|
||||
Old behavior: called sys.exit(0) on any connection failure (silent exit).
|
||||
New behavior: retries up to max_retries times, then raises the last error.
|
||||
"""
|
||||
import time
|
||||
|
||||
last_error = None
|
||||
for attempt in range(max_retries):
|
||||
try:
|
||||
conn = http.client.HTTPConnection(host, port, timeout=5)
|
||||
conn.request("GET", "/json")
|
||||
resp = conn.getresponse()
|
||||
|
||||
if resp.status != 200:
|
||||
print(f"Failed to fetch targets: {resp.status} {resp.reason}")
|
||||
sys.exit(0)
|
||||
msg = f"Failed to fetch targets: {resp.status} {resp.reason}"
|
||||
print(msg)
|
||||
raise Exception(msg)
|
||||
|
||||
data = resp.read()
|
||||
return json.loads(data)
|
||||
targets = json.loads(data)
|
||||
|
||||
except (ConnectionRefusedError, socket.timeout, http.client.CannotSendRequest, http.client.RemoteDisconnected, Exception) as e:
|
||||
print(f"Error fetching debugger targets: {e}")
|
||||
sys.exit(0)
|
||||
if attempt > 0:
|
||||
print(f"Connected to Steam debugger on attempt {attempt + 1}/{max_retries}")
|
||||
|
||||
return targets
|
||||
|
||||
except (ConnectionRefusedError, socket.timeout,
|
||||
http.client.CannotSendRequest, http.client.RemoteDisconnected,
|
||||
OSError, Exception) as e:
|
||||
last_error = e
|
||||
if attempt < max_retries - 1:
|
||||
delay = min(base_delay * (attempt + 1), 10)
|
||||
print(f"Steam debugger not ready (attempt {attempt + 1}/{max_retries}), "
|
||||
f"retrying in {delay}s... ({e})")
|
||||
time.sleep(delay)
|
||||
else:
|
||||
print(f"ERROR: Could not connect to Steam debugger at {host}:{port} "
|
||||
f"after {max_retries} attempts.")
|
||||
print(f"Make sure Steam is running with these launch options:")
|
||||
print(f" -dev -cef-enable-debugging -cef-single-process")
|
||||
raise last_error
|
||||
|
||||
finally:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user