diff --git a/src/Models/Preference.cs b/src/Models/Preference.cs index 3224a329..04362cc7 100644 --- a/src/Models/Preference.cs +++ b/src/Models/Preference.cs @@ -77,6 +77,11 @@ namespace SourceGit.Models { /// 是否启用崩溃上报 /// public bool EnableCrashReport { get; set; } = false; + + /// + /// 是否尝试使用 Windows Terminal 打开终端 + /// + public bool UseWindowsTerminal { get; set; } = false; } /// diff --git a/src/Resources/Locales/en_US.xaml b/src/Resources/Locales/en_US.xaml index b70851d3..58713562 100644 --- a/src/Resources/Locales/en_US.xaml +++ b/src/Resources/Locales/en_US.xaml @@ -360,6 +360,7 @@ Fetch remotes automatically (need restart) Restore windows Enable crash report (maybe include related path) + Use Windows Terminal to open Git terminal GIT SETTING Install Path Input path for git.exe diff --git a/src/Resources/Locales/zh_CN.xaml b/src/Resources/Locales/zh_CN.xaml index ae84d628..69212190 100644 --- a/src/Resources/Locales/zh_CN.xaml +++ b/src/Resources/Locales/zh_CN.xaml @@ -359,6 +359,7 @@ 启用定时自动拉取远程更新(重启生效) 启动时恢复上次打开的仓库 开启崩溃上报(可能涉及上报相关路径) + 使用 Windows Terminal 打开 Git 终端 GIT配置 安装路径 填写git.exe所在位置 diff --git a/src/Views/Preference.xaml b/src/Views/Preference.xaml index 62415a8d..92c24416 100644 --- a/src/Views/Preference.xaml +++ b/src/Views/Preference.xaml @@ -1,4 +1,4 @@ - - + @@ -31,24 +31,24 @@ - + - + - + - - @@ -65,6 +65,7 @@ + @@ -87,33 +88,33 @@ - + - - - + - - - - - - - + - + + + + - + - - + @@ -221,14 +229,14 @@ BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}" Icon="{StaticResource Icon.Folder.Open}"/> - + - - + @@ -248,39 +256,39 @@ BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}" Icon="{StaticResource Icon.Folder.Open}"/> - + - - - + - - - + - - - - + diff --git a/src/Views/Preference.xaml.cs b/src/Views/Preference.xaml.cs index 6a91aacc..1ec52efe 100644 --- a/src/Views/Preference.xaml.cs +++ b/src/Views/Preference.xaml.cs @@ -1,5 +1,7 @@ using Microsoft.Win32; using System; +using System.Runtime.InteropServices; +using System.Text; using System.Windows; using System.Windows.Controls; @@ -14,6 +16,13 @@ namespace SourceGit.Views { public string Email { get; set; } public string CRLF { get; set; } + // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathfindonpathw + // https://www.pinvoke.net/default.aspx/shlwapi.PathFindOnPath + [DllImport("shlwapi.dll", CharSet = CharSet.Unicode, SetLastError = false)] + private static extern bool PathFindOnPath([In, Out] StringBuilder pszFile, [In] string[] ppszOtherDirs); + + public bool EnableWindowsTerminal { get; set; } = PathFindOnPath(new StringBuilder("wt.exe"), null); + public Preference() { if (Models.Preference.Instance.IsReady) { User = new Commands.Config().Get("user.name"); @@ -26,6 +35,10 @@ namespace SourceGit.Views { CRLF = "false"; } + if (!EnableWindowsTerminal) { + Models.Preference.Instance.General.UseWindowsTerminal = false; + } + InitializeComponent(); } diff --git a/src/Views/Widgets/Dashboard.xaml.cs b/src/Views/Widgets/Dashboard.xaml.cs index 4963a54b..64f07b9f 100644 --- a/src/Views/Widgets/Dashboard.xaml.cs +++ b/src/Views/Widgets/Dashboard.xaml.cs @@ -315,11 +315,20 @@ namespace SourceGit.Views.Widgets { Models.Exception.Raise(App.Text("MissingBash")); return; } - - var start = new ProcessStartInfo(); - start.WorkingDirectory = repo.Path; - start.FileName = bash; - Process.Start(start); + if (Models.Preference.Instance.General.UseWindowsTerminal) { + Process.Start(new ProcessStartInfo { + WorkingDirectory = repo.Path, + FileName = "wt", + Arguments = bash, + UseShellExecute = false, + }); + } else { + Process.Start(new ProcessStartInfo { + WorkingDirectory = repo.Path, + FileName = bash, + UseShellExecute = true, + }); + } e.Handled = true; }