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

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