fix: Windows Terminal is not a built-in app on Windows 10

This commit is contained in:
leo 2024-04-09 11:18:16 +08:00
parent 5c9b92c3db
commit 3fd1e0ea19

View file

@ -168,7 +168,14 @@ namespace SourceGit.Native
startInfo.FileName = "cmd"; startInfo.FileName = "cmd";
break; break;
case Models.Shell.DefaultShellOfWindowsTerminal: case Models.Shell.DefaultShellOfWindowsTerminal:
startInfo.FileName = "wt"; var wt = FindWindowsTerminalApp();
if (!File.Exists(wt))
{
App.RaiseException(workdir, $"Can NOT found wt.exe on your system!");
return;
}
startInfo.FileName = FindWindowsTerminalApp();
break; break;
default: default:
App.RaiseException(workdir, $"Bad shell configuration!"); App.RaiseException(workdir, $"Bad shell configuration!");
@ -221,7 +228,8 @@ namespace SourceGit.Native
// There's two version of PowerShell : pwsh.exe (preferred) and powershell.exe (system default) // There's two version of PowerShell : pwsh.exe (preferred) and powershell.exe (system default)
private string ChoosePowerShell() private string ChoosePowerShell()
{ {
if (!string.IsNullOrEmpty(_powershellPath)) return _powershellPath; if (!string.IsNullOrEmpty(_powershellPath))
return _powershellPath;
var localMachine = Microsoft.Win32.RegistryKey.OpenBaseKey( var localMachine = Microsoft.Win32.RegistryKey.OpenBaseKey(
Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryHive.LocalMachine,
@ -248,6 +256,21 @@ namespace SourceGit.Native
return string.Empty; return string.Empty;
} }
private string FindWindowsTerminalApp()
{
if (!string.IsNullOrEmpty(_wtPath))
return _wtPath;
var finder = new StringBuilder("wt.exe", 512);
if (PathFindOnPath(finder, null))
{
_wtPath = finder.ToString();
return _wtPath;
}
return string.Empty;
}
#region EXTERNAL_EDITOR_FINDER #region EXTERNAL_EDITOR_FINDER
private string FindVSCode() private string FindVSCode()
{ {
@ -342,5 +365,6 @@ namespace SourceGit.Native
} }
private string _powershellPath = string.Empty; private string _powershellPath = string.Empty;
private string _wtPath = string.Empty;
} }
} }