Skip to content

Commit 0a6ccda

Browse files
committed
better fallback browser support
1 parent 44720fb commit 0a6ccda

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

koboldcpp.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,15 +1845,16 @@ def LaunchWebbrowser(target_url, failedmsg):
18451845
try:
18461846
import webbrowser as wb
18471847
if wb.open(target_url, autoraise=True):
1848-
return
1849-
raise RuntimeError("Cannot open default browser")
1850-
except Exception as e:
1848+
return # If successful, exit the function
1849+
raise RuntimeError("wb.open failed, using fallback")
1850+
except Exception:
18511851
try:
1852-
print(f"Browser failed to launch: {e}, attempting to use xdg-open...")
1853-
import webbrowser as wb
1854-
if wb.get('xdg-open').open(target_url, autoraise=True):
1855-
return
1856-
raise RuntimeError("Cannot open xdg-open browser")
1852+
if os.name == "posix" and "DISPLAY" in os.environ: # UNIX-like systems
1853+
import subprocess
1854+
result = subprocess.run(["xdg-open", target_url], check=True)
1855+
if result.returncode == 0:
1856+
return # fallback successful
1857+
raise RuntimeError("fallback failed")
18571858
except Exception:
18581859
print(failedmsg)
18591860
print(f"Please manually open your browser to {target_url}")

0 commit comments

Comments
 (0)