try fix webbrowser again

This commit is contained in:
Concedo 2025-01-15 00:53:24 +08:00
parent fec3246ca9
commit e07de2ea92
2 changed files with 11 additions and 11 deletions

View file

@ -1845,18 +1845,18 @@ ws ::= | " " | "\n" [ \t]{0,20}
def LaunchWebbrowser(target_url, failedmsg):
try:
import webbrowser as wb
if wb.open(target_url, autoraise=True):
return # If successful, exit the function
raise RuntimeError("wb.open failed, using fallback")
if os.name == "posix" and "DISPLAY" in os.environ: # UNIX-like systems
import subprocess
result = subprocess.run(["xdg-open", target_url], check=True)
if result.returncode == 0:
return # fallback successful
raise RuntimeError("no xdg-open")
except Exception:
try:
if os.name == "posix" and "DISPLAY" in os.environ: # UNIX-like systems
import subprocess
result = subprocess.run(["xdg-open", target_url], check=True)
if result.returncode == 0:
return # fallback successful
raise RuntimeError("fallback failed")
import webbrowser as wb
if wb.open(target_url, autoraise=True):
return # If successful, exit the function
raise RuntimeError("wb.open failed")
except Exception:
print(failedmsg)
print(f"Please manually open your browser to {target_url}")