Skip to content

Commit c9bb0c7

Browse files
committed
sessionmanager: add tracing
Add basic tracing to the `ISessionManager` implementations. This will help us identify why we think we're in a desktop session, or have a web browser available (or not). Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
1 parent 31622e6 commit c9bb0c7

6 files changed

Lines changed: 16 additions & 8 deletions

File tree

src/shared/Core/CommandContext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public CommandContext()
103103
{
104104
FileSystem = new WindowsFileSystem();
105105
Environment = new WindowsEnvironment(FileSystem);
106-
SessionManager = new WindowsSessionManager(Environment, FileSystem);
106+
SessionManager = new WindowsSessionManager(Trace, Environment, FileSystem);
107107
ProcessManager = new WindowsProcessManager(Trace2);
108108
Terminal = new WindowsTerminal(Trace, Trace2);
109109
string gitPath = GetGitPath(Environment, FileSystem, Trace);
@@ -120,7 +120,7 @@ public CommandContext()
120120
{
121121
FileSystem = new MacOSFileSystem();
122122
Environment = new MacOSEnvironment(FileSystem);
123-
SessionManager = new MacOSSessionManager(Environment, FileSystem);
123+
SessionManager = new MacOSSessionManager(Trace, Environment, FileSystem);
124124
ProcessManager = new ProcessManager(Trace2);
125125
Terminal = new MacOSTerminal(Trace, Trace2);
126126
string gitPath = GetGitPath(Environment, FileSystem, Trace);
@@ -137,7 +137,7 @@ public CommandContext()
137137
{
138138
FileSystem = new LinuxFileSystem();
139139
Environment = new PosixEnvironment(FileSystem);
140-
SessionManager = new LinuxSessionManager(Environment, FileSystem);
140+
SessionManager = new LinuxSessionManager(Trace, Environment, FileSystem);
141141
ProcessManager = new ProcessManager(Trace2);
142142
Terminal = new LinuxTerminal(Trace, Trace2);
143143
string gitPath = GetGitPath(Environment, FileSystem, Trace);

src/shared/Core/ISessionManager.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,17 @@ public static void OpenBrowser(this ISessionManager sm, string url)
4040

4141
public abstract class SessionManager : ISessionManager
4242
{
43+
protected ITrace Trace { get; }
4344
protected IEnvironment Environment { get; }
4445
protected IFileSystem FileSystem { get; }
4546

46-
protected SessionManager(IEnvironment env, IFileSystem fs)
47+
protected SessionManager(ITrace trace, IEnvironment env, IFileSystem fs)
4748
{
49+
EnsureArgument.NotNull(trace, nameof(trace));
4850
EnsureArgument.NotNull(env, nameof(env));
4951
EnsureArgument.NotNull(fs, nameof(fs));
5052

53+
Trace = trace;
5154
Environment = env;
5255
FileSystem = fs;
5356
}
@@ -69,6 +72,7 @@ public void OpenBrowser(Uri uri)
6972

7073
protected virtual void OpenBrowserInternal(string url)
7174
{
75+
Trace.WriteLine("Opening browser using framework shell-execute: " + url);
7276
var psi = new ProcessStartInfo(url) { UseShellExecute = true };
7377
Process.Start(psi);
7478
}

src/shared/Core/Interop/Linux/LinuxSessionManager.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 URL handler: " + shellExecPath);
45+
4446
var psi = new ProcessStartInfo(shellExecPath, url)
4547
{
4648
RedirectStandardOutput = true,
@@ -56,6 +58,7 @@ private bool GetWebBrowserAvailable()
5658
// We need a shell execute handler to be able to launch to browser
5759
if (!TryGetShellExecuteHandler(Environment, out _))
5860
{
61+
Trace.WriteLine("Could not locate a shell execute handler for Linux - browser is not available.");
5962
return false;
6063
}
6164

@@ -82,6 +85,7 @@ private bool GetWebBrowserAvailable()
8285
if (WslUtils.IsWslDistribution(Environment, FileSystem, out _) &&
8386
WslUtils.GetWindowsSessionId(FileSystem) == 0)
8487
{
88+
Trace.WriteLine("This is a WSL distribution, but Windows session 0 was detected - browser is not available.");
8589
return false;
8690
}
8791

src/shared/Core/Interop/MacOS/MacOSSessionManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace GitCredentialManager.Interop.MacOS
55
{
66
public class MacOSSessionManager : PosixSessionManager
77
{
8-
public MacOSSessionManager(IEnvironment env, IFileSystem fs) : base(env, fs)
8+
public MacOSSessionManager(ITrace trace, IEnvironment env, IFileSystem fs) : base(trace, env, fs)
99
{
1010
PlatformUtils.EnsureMacOS();
1111
}

src/shared/Core/Interop/Posix/PosixSessionManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace GitCredentialManager.Interop.Posix
22
{
33
public abstract class PosixSessionManager : SessionManager
44
{
5-
protected PosixSessionManager(IEnvironment env, IFileSystem fs) : base(env, fs)
5+
protected PosixSessionManager(ITrace trace, IEnvironment env, IFileSystem fs) : base(trace, env, fs)
66
{
77
PlatformUtils.EnsurePosix();
88
}

src/shared/Core/Interop/Windows/WindowsSessionManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace GitCredentialManager.Interop.Windows
55
{
66
public class WindowsSessionManager : SessionManager
77
{
8-
public WindowsSessionManager(IEnvironment env, IFileSystem fs) : base(env, fs)
8+
public WindowsSessionManager(ITrace trace, IEnvironment env, IFileSystem fs) : base(trace, env, fs)
99
{
1010
PlatformUtils.EnsureWindows();
1111
}

0 commit comments

Comments
 (0)