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

@ -1463,7 +1463,7 @@
}, },
"voice": { "voice": {
"type": "string", "type": "string",
"description": "The voice to use when generating the audio. You can enter anything you like, a qunique speaker will be generated." "description": "The voice to use when generating the audio. You can enter anything you like, a unique speaker will be generated. There are a few preset voices you can use: kobo,cheery,sleepy,tutor,shouty,bored,record"
} }
}, },
"type": "object" "type": "object"

View file

@ -1844,19 +1844,19 @@ ws ::= | " " | "\n" [ \t]{0,20}
return genparams return genparams
def LaunchWebbrowser(target_url, failedmsg): 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")
except Exception:
try: try:
if os.name == "posix" and "DISPLAY" in os.environ: # UNIX-like systems if os.name == "posix" and "DISPLAY" in os.environ: # UNIX-like systems
import subprocess import subprocess
result = subprocess.run(["xdg-open", target_url], check=True) result = subprocess.run(["xdg-open", target_url], check=True)
if result.returncode == 0: if result.returncode == 0:
return # fallback successful return # fallback successful
raise RuntimeError("fallback failed") raise RuntimeError("no xdg-open")
except Exception:
try:
import webbrowser as wb
if wb.open(target_url, autoraise=True):
return # If successful, exit the function
raise RuntimeError("wb.open 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}")