From 4deac98c4eb8429d750d5ddfda8fede82145933c Mon Sep 17 00:00:00 2001 From: Aikawa Yataro Date: Mon, 16 Sep 2024 08:51:39 +0000 Subject: [PATCH 1/4] fix: crash when trying to open terminal from the Welcome screen --- src/Native/Linux.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Native/Linux.cs b/src/Native/Linux.cs index 9537a39a..30aa7cc9 100644 --- a/src/Native/Linux.cs +++ b/src/Native/Linux.cs @@ -78,7 +78,8 @@ namespace SourceGit.Native } var startInfo = new ProcessStartInfo(); - startInfo.WorkingDirectory = string.IsNullOrEmpty(workdir) ? "~" : workdir; + var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + startInfo.WorkingDirectory = string.IsNullOrEmpty(workdir) ? home : workdir; startInfo.FileName = OS.ShellOrTerminal; Process.Start(startInfo); } From 53c915578e926f0d21472d2ecacb878df50078f5 Mon Sep 17 00:00:00 2001 From: Aikawa Yataro Date: Mon, 16 Sep 2024 11:55:50 +0000 Subject: [PATCH 2/4] 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; } From 736ad02991700411a7268b74093f95599dace90b Mon Sep 17 00:00:00 2001 From: Aikawa Yataro Date: Mon, 16 Sep 2024 12:03:56 +0000 Subject: [PATCH 3/4] enhance: allow to specify custom terminal --- src/Models/ShellOrTerminal.cs | 1 + src/Native/Linux.cs | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Models/ShellOrTerminal.cs b/src/Models/ShellOrTerminal.cs index fa3a207b..02b294a0 100644 --- a/src/Models/ShellOrTerminal.cs +++ b/src/Models/ShellOrTerminal.cs @@ -54,6 +54,7 @@ namespace SourceGit.Models new ShellOrTerminal("deepin-terminal", "Deepin Terminal", "deepin-terminal"), new ShellOrTerminal("mate-terminal", "MATE Terminal", "mate-terminal"), new ShellOrTerminal("foot", "Foot", "foot"), + new ShellOrTerminal("custom", "Custom", ""), }; } } diff --git a/src/Native/Linux.cs b/src/Native/Linux.cs index 191f4ddd..16fd1b78 100644 --- a/src/Native/Linux.cs +++ b/src/Native/Linux.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq.Expressions; using System.Runtime.Versioning; using Avalonia; @@ -27,6 +26,11 @@ namespace SourceGit.Native public string FindTerminal(Models.ShellOrTerminal shell) { + if (string.IsNullOrEmpty(shell.Exec)) + { + return string.Empty; + } + var pathVariable = Environment.GetEnvironmentVariable("PATH") ?? string.Empty; var pathes = pathVariable.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries); foreach (var path in pathes) From 54ab6259319d5ce3febccab594351836a422ab68 Mon Sep 17 00:00:00 2001 From: Aikawa Yataro Date: Tue, 17 Sep 2024 07:20:17 +0000 Subject: [PATCH 4/4] enhance: select any terminal when none is set --- src/ViewModels/Preference.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index 6887e6c9..b62e3720 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -41,6 +41,22 @@ namespace SourceGit.ViewModels if (!_instance.IsGitConfigured()) _instance.GitInstallPath = Native.OS.FindGitExecutable(); + if (!_instance.IsTerminalConfigured()) + { + for (var i = 0; i < Models.ShellOrTerminal.Supported.Count; i++) + { + _instance.ShellOrTerminal = i; + if (string.IsNullOrEmpty(_instance.ShellOrTerminalPath)) + { + _instance.ShellOrTerminal = -1; + } + else + { + break; + } + } + } + if (_instance.Workspaces.Count == 0) _instance.Workspaces.Add(new Workspace() { Name = "Default", Color = 4278221015 }); @@ -380,6 +396,11 @@ namespace SourceGit.ViewModels return !string.IsNullOrEmpty(path) && File.Exists(path); } + public bool IsTerminalConfigured() + { + return ShellOrTerminal != -1; + } + public bool ShouldCheck4UpdateOnStartup() { if (!_check4UpdatesOnStartup)