better fallback browser support

This commit is contained in:
Concedo 2025-01-14 18:59:17 +08:00
parent 44720fb34c
commit 0a6ccda203

View file

@ -1845,15 +1845,16 @@ def LaunchWebbrowser(target_url, failedmsg):
try: try:
import webbrowser as wb import webbrowser as wb
if wb.open(target_url, autoraise=True): if wb.open(target_url, autoraise=True):
return return # If successful, exit the function
raise RuntimeError("Cannot open default browser") raise RuntimeError("wb.open failed, using fallback")
except Exception as e: except Exception:
try: try:
print(f"Browser failed to launch: {e}, attempting to use xdg-open...") if os.name == "posix" and "DISPLAY" in os.environ: # UNIX-like systems
import webbrowser as wb import subprocess
if wb.get('xdg-open').open(target_url, autoraise=True): result = subprocess.run(["xdg-open", target_url], check=True)
return if result.returncode == 0:
raise RuntimeError("Cannot open xdg-open browser") return # fallback successful
raise RuntimeError("fallback failed")
except Exception: except Exception:
print(failedmsg) print(failedmsg)
print(f"Please manually open your browser to {target_url}") print(f"Please manually open your browser to {target_url}")