Merge pull request #480 from aikawayataro/terminal-fixes

Few terminal fixes
This commit is contained in:
leo 2024-09-17 21:21:40 +08:00 committed by GitHub
commit 65c2087f6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 41 additions and 6 deletions

View file

@ -54,6 +54,7 @@ namespace SourceGit.Models
new ShellOrTerminal("deepin-terminal", "Deepin Terminal", "deepin-terminal"), new ShellOrTerminal("deepin-terminal", "Deepin Terminal", "deepin-terminal"),
new ShellOrTerminal("mate-terminal", "MATE Terminal", "mate-terminal"), new ShellOrTerminal("mate-terminal", "MATE Terminal", "mate-terminal"),
new ShellOrTerminal("foot", "Foot", "foot"), new ShellOrTerminal("foot", "Foot", "foot"),
new ShellOrTerminal("custom", "Custom", ""),
}; };
} }
} }

View file

@ -26,6 +26,11 @@ namespace SourceGit.Native
public string FindTerminal(Models.ShellOrTerminal shell) public string FindTerminal(Models.ShellOrTerminal shell)
{ {
if (string.IsNullOrEmpty(shell.Exec))
{
return string.Empty;
}
var pathVariable = Environment.GetEnvironmentVariable("PATH") ?? string.Empty; var pathVariable = Environment.GetEnvironmentVariable("PATH") ?? string.Empty;
var pathes = pathVariable.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries); var pathes = pathVariable.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries);
foreach (var path in pathes) foreach (var path in pathes)
@ -71,16 +76,24 @@ namespace SourceGit.Native
public void OpenTerminal(string workdir) 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; return;
} }
var startInfo = new ProcessStartInfo(); 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; startInfo.FileName = OS.ShellOrTerminal;
Process.Start(startInfo); try
{
Process.Start(startInfo);
}
catch (Exception e)
{
App.RaiseException(workdir, e.Message);
}
} }
public void OpenWithDefaultEditor(string file) public void OpenWithDefaultEditor(string file)

View file

@ -95,7 +95,7 @@ namespace SourceGit.Native
public static void OpenTerminal(string workdir) public static void OpenTerminal(string workdir)
{ {
if (string.IsNullOrEmpty(ShellOrTerminal)) 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 else
_backend.OpenTerminal(workdir); _backend.OpenTerminal(workdir);
} }

View file

@ -160,7 +160,7 @@ namespace SourceGit.Native
{ {
if (string.IsNullOrEmpty(OS.ShellOrTerminal) || !File.Exists(OS.ShellOrTerminal)) 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; return;
} }

View file

@ -41,6 +41,22 @@ namespace SourceGit.ViewModels
if (!_instance.IsGitConfigured()) if (!_instance.IsGitConfigured())
_instance.GitInstallPath = Native.OS.FindGitExecutable(); _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) if (_instance.Workspaces.Count == 0)
_instance.Workspaces.Add(new Workspace() { Name = "Default", Color = 4278221015 }); _instance.Workspaces.Add(new Workspace() { Name = "Default", Color = 4278221015 });
@ -380,6 +396,11 @@ namespace SourceGit.ViewModels
return !string.IsNullOrEmpty(path) && File.Exists(path); return !string.IsNullOrEmpty(path) && File.Exists(path);
} }
public bool IsTerminalConfigured()
{
return ShellOrTerminal != -1;
}
public bool ShouldCheck4UpdateOnStartup() public bool ShouldCheck4UpdateOnStartup()
{ {
if (!_check4UpdatesOnStartup) if (!_check4UpdatesOnStartup)