From 79cf73e8af0b686b869479beb306ca364e18bf2b Mon Sep 17 00:00:00 2001 From: Sina Hinderks Date: Mon, 18 Aug 2025 04:36:17 +0200 Subject: [PATCH] fix: Open Terminal on Welcome Page crashed (Windows) (#1740) Trying to open the Windows Terminal on the Welcome Page crashed with a `NullReferenceException`. The code for Windows after the fix is similar to the corresponding code for Linux. --- src/Native/Windows.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Native/Windows.cs b/src/Native/Windows.cs index 5ba027bc..d8b7286e 100644 --- a/src/Native/Windows.cs +++ b/src/Native/Windows.cs @@ -203,19 +203,23 @@ namespace SourceGit.Native public void OpenTerminal(string workdir) { - if (!File.Exists(OS.ShellOrTerminal)) + var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + var cwd = string.IsNullOrEmpty(workdir) ? home : workdir; + var terminal = OS.ShellOrTerminal; + + if (!File.Exists(terminal)) { App.RaiseException(workdir, "Terminal is not specified! Please confirm that the correct shell/terminal has been configured."); return; } var startInfo = new ProcessStartInfo(); - startInfo.WorkingDirectory = workdir; - startInfo.FileName = OS.ShellOrTerminal; + startInfo.WorkingDirectory = cwd; + startInfo.FileName = terminal; // Directly launching `Windows Terminal` need to specify the `-d` parameter - if (OS.ShellOrTerminal.EndsWith("wt.exe", StringComparison.OrdinalIgnoreCase)) - startInfo.Arguments = $"-d {workdir.Quoted()}"; + if (terminal.EndsWith("wt.exe", StringComparison.OrdinalIgnoreCase)) + startInfo.Arguments = $"-d {cwd.Quoted()}"; Process.Start(startInfo); }