mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-20 11:44:59 +00:00
140 lines
4.6 KiB
C#
140 lines
4.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Runtime.Versioning;
|
|
|
|
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Platform;
|
|
|
|
namespace SourceGit.Native
|
|
{
|
|
[SupportedOSPlatform("linux")]
|
|
internal class Linux : OS.IBackend
|
|
{
|
|
public void SetupApp(AppBuilder builder)
|
|
{
|
|
builder.With(new X11PlatformOptions() { EnableIme = true });
|
|
}
|
|
|
|
public void SetupWindow(Window window)
|
|
{
|
|
if (OS.UseSystemWindowFrame)
|
|
{
|
|
window.ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.Default;
|
|
window.ExtendClientAreaToDecorationsHint = false;
|
|
}
|
|
else
|
|
{
|
|
window.ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.NoChrome;
|
|
window.ExtendClientAreaToDecorationsHint = true;
|
|
window.Classes.Add("custom_window_frame");
|
|
}
|
|
}
|
|
|
|
public string FindGitExecutable()
|
|
{
|
|
return FindExecutable("git");
|
|
}
|
|
|
|
public string FindTerminal(Models.ShellOrTerminal shell)
|
|
{
|
|
if (shell.Type.Equals("custom", StringComparison.Ordinal))
|
|
return string.Empty;
|
|
|
|
return FindExecutable(shell.Exec);
|
|
}
|
|
|
|
public List<Models.ExternalTool> FindExternalTools()
|
|
{
|
|
var finder = new Models.ExternalToolsFinder();
|
|
finder.VSCode(() => FindExecutable("code"));
|
|
finder.VSCodeInsiders(() => FindExecutable("code-insiders"));
|
|
finder.VSCodium(() => FindExecutable("codium"));
|
|
finder.Fleet(FindJetBrainsFleet);
|
|
finder.FindJetBrainsFromToolbox(() => $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}/JetBrains/Toolbox");
|
|
finder.SublimeText(() => FindExecutable("subl"));
|
|
finder.Zed(() => FindExecutable("zeditor"));
|
|
return finder.Founded;
|
|
}
|
|
|
|
public void OpenBrowser(string url)
|
|
{
|
|
Process.Start("xdg-open", $"\"{url}\"");
|
|
}
|
|
|
|
public void OpenInFileManager(string path, bool select)
|
|
{
|
|
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 home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
|
var cwd = string.IsNullOrEmpty(workdir) ? home : workdir;
|
|
var terminal = OS.ShellOrTerminal;
|
|
|
|
var startInfo = new ProcessStartInfo();
|
|
startInfo.WorkingDirectory = cwd;
|
|
startInfo.FileName = terminal;
|
|
|
|
if (terminal.EndsWith("wezterm", StringComparison.OrdinalIgnoreCase))
|
|
startInfo.Arguments = $"start --cwd \"{cwd}\"";
|
|
else if (terminal.EndsWith("ptyxis", StringComparison.OrdinalIgnoreCase))
|
|
startInfo.Arguments = $"--new-window --working-directory=\"{cwd}\"";
|
|
|
|
try
|
|
{
|
|
Process.Start(startInfo);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
App.RaiseException(workdir, $"Failed to start '{OS.ShellOrTerminal}'. Reason: {e.Message}");
|
|
}
|
|
}
|
|
|
|
public void OpenWithDefaultEditor(string file)
|
|
{
|
|
var proc = Process.Start("xdg-open", $"\"{file}\"");
|
|
if (proc != null)
|
|
{
|
|
proc.WaitForExit();
|
|
|
|
if (proc.ExitCode != 0)
|
|
App.RaiseException("", $"Failed to open \"{file}\"");
|
|
|
|
proc.Close();
|
|
}
|
|
}
|
|
|
|
private string FindExecutable(string filename)
|
|
{
|
|
var pathVariable = Environment.GetEnvironmentVariable("PATH") ?? string.Empty;
|
|
var pathes = pathVariable.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries);
|
|
foreach (var path in pathes)
|
|
{
|
|
var test = Path.Combine(path, filename);
|
|
if (File.Exists(test))
|
|
return test;
|
|
}
|
|
|
|
return string.Empty;
|
|
}
|
|
|
|
private string FindJetBrainsFleet()
|
|
{
|
|
var path = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}/JetBrains/Toolbox/apps/fleet/bin/Fleet";
|
|
return File.Exists(path) ? path : FindExecutable("fleet");
|
|
}
|
|
}
|
|
}
|