From 53c915578e926f0d21472d2ecacb878df50078f5 Mon Sep 17 00:00:00 2001 From: Aikawa Yataro Date: Mon, 16 Sep 2024 11:55:50 +0000 Subject: [PATCH] enhance: allow terminal without full path and adjust error message --- src/Native/Linux.cs | 14 +++++++++++--- src/Native/OS.cs | 2 +- src/Native/Windows.cs | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Native/Linux.cs b/src/Native/Linux.cs index 30aa7cc9..191f4ddd 100644 --- a/src/Native/Linux.cs +++ b/src/Native/Linux.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq.Expressions; using System.Runtime.Versioning; using Avalonia; @@ -71,9 +72,9 @@ namespace SourceGit.Native public void OpenTerminal(string workdir) { - if (string.IsNullOrEmpty(OS.ShellOrTerminal) || !File.Exists(OS.ShellOrTerminal)) + if (string.IsNullOrEmpty(OS.ShellOrTerminal)) { - App.RaiseException(workdir, $"Can not found terminal! Please confirm that the correct shell/terminal has been configured."); + App.RaiseException(workdir, $"Terminal is not specified! Please confirm that the correct shell/terminal has been configured."); return; } @@ -81,7 +82,14 @@ namespace SourceGit.Native var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); startInfo.WorkingDirectory = string.IsNullOrEmpty(workdir) ? home : workdir; startInfo.FileName = OS.ShellOrTerminal; - Process.Start(startInfo); + try + { + Process.Start(startInfo); + } + catch (Exception e) + { + App.RaiseException(workdir, e.Message); + } } public void OpenWithDefaultEditor(string file) diff --git a/src/Native/OS.cs b/src/Native/OS.cs index 87655798..7df0b3ae 100644 --- a/src/Native/OS.cs +++ b/src/Native/OS.cs @@ -95,7 +95,7 @@ namespace SourceGit.Native public static void OpenTerminal(string workdir) { if (string.IsNullOrEmpty(ShellOrTerminal)) - App.RaiseException(workdir, $"Can not found terminal! Please confirm that the correct shell/terminal has been configured."); + App.RaiseException(workdir, $"Terminal is not specified! Please confirm that the correct shell/terminal has been configured."); else _backend.OpenTerminal(workdir); } diff --git a/src/Native/Windows.cs b/src/Native/Windows.cs index 19362d0c..13438e02 100644 --- a/src/Native/Windows.cs +++ b/src/Native/Windows.cs @@ -160,7 +160,7 @@ namespace SourceGit.Native { if (string.IsNullOrEmpty(OS.ShellOrTerminal) || !File.Exists(OS.ShellOrTerminal)) { - App.RaiseException(workdir, $"Can not found terminal! Please confirm that the correct shell/terminal has been configured."); + App.RaiseException(workdir, $"Terminal is not specified! Please confirm that the correct shell/terminal has been configured."); return; }