@@ -158,38 +158,48 @@ def debuglog(enabled, msg):
158158 timestamp = time .strftime ("%Y-%m-%d %H:%M:%S" , time .localtime (t )) + ".{:03d}" .format (int (t % 1 * 1000 ))
159159 print ("[{}] [DEBUG] {}" .format (timestamp , msg ))
160160
161+ def is_browser_available ():
162+ """Returns True if the current environment can likely open a local browser."""
163+ try :
164+ if IS_WINDOWS :
165+ return True
166+ # Check for WSL environment
167+ if platform .system () == 'Linux' :
168+ try :
169+ if os .path .exists ('/proc/version' ):
170+ with open ('/proc/version' , 'r' ) as f :
171+ if 'microsoft' in f .read ().lower ():
172+ return True
173+ except :
174+ pass
175+ # Linux: Check if DISPLAY or WAYLAND_DISPLAY is set
176+ if os .environ .get ('DISPLAY' ) or os .environ .get ('WAYLAND_DISPLAY' ):
177+ return True
178+ elif platform .system () == 'Darwin' :
179+ # macOS: Check if likely in a GUI session (not over SSH)
180+ if not os .environ .get ('SSH_CLIENT' ) and not os .environ .get ('SSH_TTY' ):
181+ return True
182+ except :
183+ pass
184+ return False
185+
161186def open_vnc_page (web_port ):
162187 """Automatically open the VNC web page in the browser based on environment."""
163- if not web_port :
188+ if not web_port or not is_browser_available () :
164189 return
165190
166191 def _open_in_background ():
167192 # Give VNC proxy/QEMU a moment to initialize ports properly
168193 time .sleep (1 )
169194 url = "http://localhost:{}" .format (web_port )
170195 try :
171- # Check for WSL environment
172- is_wsl = False
173- if platform .system () == 'Linux' :
174- try :
175- if os .path .exists ('/proc/version' ):
176- with open ('/proc/version' , 'r' ) as f :
177- if 'microsoft' in f .read ().lower ():
178- is_wsl = True
179- except :
180- pass
181-
182- if IS_WINDOWS or is_wsl :
183- # Windows or WSL: Use explorer.exe to open the URL
196+ if IS_WINDOWS or (platform .system () == 'Linux' and 'microsoft' in open ('/proc/version' ).read ().lower ()):
197+ # Windows or WSL
184198 subprocess .Popen (['explorer.exe' , url ], shell = IS_WINDOWS )
185199 elif platform .system () == 'Darwin' :
186- # macOS: Open if likely in a GUI session (not over SSH)
187- if not os .environ .get ('SSH_CLIENT' ) and not os .environ .get ('SSH_TTY' ):
188- subprocess .Popen (['open' , url ], stdout = DEVNULL , stderr = DEVNULL )
200+ subprocess .Popen (['open' , url ], stdout = DEVNULL , stderr = DEVNULL )
189201 elif platform .system () == 'Linux' :
190- # Linux: Open if DISPLAY or WAYLAND_DISPLAY is set
191- if os .environ .get ('DISPLAY' ) or os .environ .get ('WAYLAND_DISPLAY' ):
192- subprocess .Popen (['xdg-open' , url ], stdout = DEVNULL , stderr = DEVNULL )
202+ subprocess .Popen (['xdg-open' , url ], stdout = DEVNULL , stderr = DEVNULL )
193203 except Exception :
194204 pass
195205
@@ -4181,7 +4191,15 @@ def fail_with_output(reason):
41814191 log ("Started QEMU (PID: {})" .format (proc .pid ))
41824192
41834193 tail_stop_event = threading .Event ()
4184- if config ['debug' ] and serial_log_file :
4194+ should_tail = config ['debug' ] and serial_log_file
4195+
4196+ # If we are likely to open a browser for Web VNC/Console, don't tail serial to terminal
4197+ # to avoid clutter and redundant output.
4198+ if should_tail and web_port and is_browser_available ():
4199+ should_tail = False
4200+ debuglog (config ['debug' ], "Skipping serial terminal tail because Web VNC/Console is available." )
4201+
4202+ if should_tail :
41854203 t = threading .Thread (target = tail_serial_log , args = (serial_log_file , tail_stop_event ))
41864204 t .daemon = True
41874205 t .start ()
0 commit comments