2024-03-27 23:48:20 -07:00
|
|
|
|
using System;
|
2024-04-05 22:14:22 -07:00
|
|
|
|
using System.Collections.Generic;
|
2024-03-27 23:48:20 -07:00
|
|
|
|
using System.Diagnostics;
|
2024-03-20 00:36:10 -07:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Runtime.Versioning;
|
|
|
|
|
|
|
|
|
|
using Avalonia;
|
|
|
|
|
using Avalonia.Dialogs;
|
2024-03-21 05:55:08 -07:00
|
|
|
|
using Avalonia.Media;
|
2024-03-20 00:36:10 -07:00
|
|
|
|
|
|
|
|
|
namespace SourceGit.Native
|
|
|
|
|
{
|
|
|
|
|
[SupportedOSPlatform("linux")]
|
|
|
|
|
internal class Linux : OS.IBackend
|
|
|
|
|
{
|
|
|
|
|
public void SetupApp(AppBuilder builder)
|
|
|
|
|
{
|
2024-03-21 05:55:08 -07:00
|
|
|
|
builder.With(new FontManagerOptions()
|
|
|
|
|
{
|
|
|
|
|
DefaultFamilyName = "fonts:SourceGit#JetBrains Mono",
|
|
|
|
|
});
|
|
|
|
|
|
2024-03-20 00:36:10 -07:00
|
|
|
|
// Free-desktop file picker has an extra black background panel.
|
|
|
|
|
builder.UseManagedSystemDialogs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string FindGitExecutable()
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (File.Exists("/usr/bin/git"))
|
|
|
|
|
return "/usr/bin/git";
|
2024-03-20 00:36:10 -07:00
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-08 02:39:52 -07:00
|
|
|
|
public List<Models.ExternalTool> FindExternalTools()
|
2024-03-20 00:36:10 -07:00
|
|
|
|
{
|
2024-04-08 02:39:52 -07:00
|
|
|
|
var finder = new Models.ExternalToolsFinder();
|
2024-04-07 02:56:53 -07:00
|
|
|
|
finder.VSCode(() => "/usr/share/code/code");
|
|
|
|
|
finder.VSCodeInsiders(() => "/usr/share/code-insiders/code-insiders");
|
|
|
|
|
finder.Fleet(() => $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}/JetBrains/Toolbox/apps/fleet/bin/Fleet");
|
|
|
|
|
finder.SublimeText(() => File.Exists("/usr/bin/subl") ? "/usr/bin/subl" : "/usr/local/bin/subl");
|
2024-04-08 02:39:52 -07:00
|
|
|
|
return finder.Founded;
|
2024-03-27 22:49:32 -07:00
|
|
|
|
}
|
2024-03-20 00:36:10 -07:00
|
|
|
|
|
|
|
|
|
public void OpenBrowser(string url)
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists("/usr/bin/xdg-open"))
|
|
|
|
|
{
|
|
|
|
|
App.RaiseException("", $"You should install xdg-open first!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Process.Start("xdg-open", $"\"{url}\"");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OpenInFileManager(string path, bool select)
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists("/usr/bin/xdg-open"))
|
|
|
|
|
{
|
|
|
|
|
App.RaiseException("", $"You should install xdg-open first!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Directory.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
Process.Start("xdg-open", $"\"{path}\"");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var dir = Path.GetDirectoryName(path);
|
|
|
|
|
if (Directory.Exists(dir))
|
|
|
|
|
{
|
|
|
|
|
Process.Start("xdg-open", $"\"{dir}\"");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OpenTerminal(string workdir)
|
|
|
|
|
{
|
|
|
|
|
var dir = string.IsNullOrEmpty(workdir) ? "~" : workdir;
|
|
|
|
|
if (File.Exists("/usr/bin/gnome-terminal"))
|
|
|
|
|
{
|
|
|
|
|
Process.Start("/usr/bin/gnome-terminal", $"--working-directory=\"{dir}\"");
|
|
|
|
|
}
|
|
|
|
|
else if (File.Exists("/usr/bin/konsole"))
|
|
|
|
|
{
|
|
|
|
|
Process.Start("/usr/bin/konsole", $"--workdir \"{dir}\"");
|
|
|
|
|
}
|
|
|
|
|
else if (File.Exists("/usr/bin/xfce4-terminal"))
|
|
|
|
|
{
|
|
|
|
|
Process.Start("/usr/bin/xfce4-terminal", $"--working-directory=\"{dir}\"");
|
|
|
|
|
}
|
2024-04-08 22:06:27 -07:00
|
|
|
|
else if (File.Exists("/usr/bin/deepin-terminal"))
|
|
|
|
|
{
|
2024-04-08 22:59:55 -07:00
|
|
|
|
Process.Start("/usr/bin/deepin-terminal", $"--work-directory \"{dir}\"");
|
2024-04-08 22:06:27 -07:00
|
|
|
|
}
|
2024-03-20 00:36:10 -07:00
|
|
|
|
else
|
|
|
|
|
{
|
2024-04-08 22:06:27 -07:00
|
|
|
|
App.RaiseException(dir, $"Only supports gnome-terminal/konsole/xfce4-terminal/deepin-terminal!");
|
2024-03-20 00:36:10 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OpenWithDefaultEditor(string file)
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists("/usr/bin/xdg-open"))
|
|
|
|
|
{
|
|
|
|
|
App.RaiseException("", $"You should install xdg-open first!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var proc = Process.Start("xdg-open", $"\"{file}\"");
|
|
|
|
|
proc.WaitForExit();
|
|
|
|
|
|
|
|
|
|
if (proc.ExitCode != 0)
|
|
|
|
|
{
|
|
|
|
|
App.RaiseException("", $"Failed to open \"{file}\"");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
proc.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|