File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff 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 } " )
You can’t perform that action at this time.
0 commit comments