@@ -8,7 +8,7 @@ public class LinuxSessionManager : PosixSessionManager
88{
99 private bool ? _isWebBrowserAvailable ;
1010
11- public LinuxSessionManager ( IEnvironment env , IFileSystem fs ) : base ( env , fs )
11+ public LinuxSessionManager ( ITrace trace , IEnvironment env , IFileSystem fs ) : base ( trace , env , fs )
1212 {
1313 PlatformUtils . EnsureLinux ( ) ;
1414 }
@@ -41,6 +41,8 @@ protected override void OpenBrowserInternal(string url)
4141 throw new Exception ( "Failed to locate a utility to launch the default web browser." ) ;
4242 }
4343
44+ Trace . WriteLine ( $ "Opening browser using '{ shellExecPath } : { url } ") ;
45+
4446 var psi = new ProcessStartInfo ( shellExecPath , url )
4547 {
4648 RedirectStandardOutput = true ,
@@ -53,44 +55,47 @@ protected override void OpenBrowserInternal(string url)
5355
5456 private bool GetWebBrowserAvailable ( )
5557 {
58+ // We need a shell execute handler to be able to launch to browser
59+ if ( ! TryGetShellExecuteHandler ( Environment , out _ ) )
60+ {
61+ Trace . WriteLine ( "Could not locate a shell execute handler for Linux - browser is not available." ) ;
62+ return false ;
63+ }
64+
5665 // If this is a Windows Subsystem for Linux distribution we may
57- // be able to launch the web browser of the host Windows OS.
66+ // be able to launch the web browser of the host Windows OS, but
67+ // there are further checks to do on the Windows host's session.
68+ //
69+ // If we are in Windows logon session 0 then the user can never interact,
70+ // even in the WinSta0 window station. This is typical when SSH-ing into a
71+ // Windows 10+ machine using the default OpenSSH Server configuration,
72+ // which runs in the 'services' session 0.
73+ //
74+ // If we're in any other session, and in the WinSta0 window station then
75+ // the user can possibly interact. However, since it's hard to determine
76+ // the window station from PowerShell cmdlets (we'd need to write P/Invoke
77+ // code and that's just messy and too many levels of indirection quite
78+ // frankly!) we just assume any non session 0 is interactive.
79+ //
80+ // This assumption doesn't hold true if the user has changed the user that
81+ // the OpenSSH Server service runs as (not a built-in NT service) *AND*
82+ // they've SSH-ed into the Windows host (and then started a WSL shell).
83+ // This feels like a very small subset of users...
84+ //
5885 if ( WslUtils . IsWslDistribution ( Environment , FileSystem , out _ ) )
5986 {
60- // We need a shell execute handler to be able to launch to browser
61- if ( ! TryGetShellExecuteHandler ( Environment , out _ ) )
62- {
63- return false ;
64- }
65-
66- //
67- // If we are in Windows logon session 0 then the user can never interact,
68- // even in the WinSta0 window station. This is typical when SSH-ing into a
69- // Windows 10+ machine using the default OpenSSH Server configuration,
70- // which runs in the 'services' session 0.
71- //
72- // If we're in any other session, and in the WinSta0 window station then
73- // the user can possibly interact. However, since it's hard to determine
74- // the window station from PowerShell cmdlets (we'd need to write P/Invoke
75- // code and that's just messy and too many levels of indirection quite
76- // frankly!) we just assume any non session 0 is interactive.
77- //
78- // This assumption doesn't hold true if the user has changed the user that
79- // the OpenSSH Server service runs as (not a built-in NT service) *AND*
80- // they've SSH-ed into the Windows host (and then started a WSL shell).
81- // This feels like a very small subset of users...
82- //
8387 if ( WslUtils . GetWindowsSessionId ( FileSystem ) == 0 )
8488 {
89+ Trace . WriteLine ( "This is a WSL distribution, but Windows session 0 was detected - browser is not available." ) ;
8590 return false ;
8691 }
8792
88- // If we are not in session 0, or we cannot get the Windows session ID,
89- // assume that we *CAN* launch the browser so that users are never blocked.
93+ // Not on session 0 - we assume the user can interact with browser on Windows.
94+ Trace . WriteLine ( "This is a WSL distribution - browser is available." ) ;
9095 return true ;
9196 }
9297
93- // We require an interactive desktop session to be able to launch a browser
98+ // We need a desktop session to be able to launch the browser in the general case
9499 return IsDesktopSession ;
95100 }
96101
0 commit comments