sourcegit/src/SourceGit/Native/OS.cs

119 lines
3.1 KiB
C#
Raw Normal View History

using System;
using System.Diagnostics;
using Avalonia;
namespace SourceGit.Native
{
public static class OS
{
public interface IBackend
{
void SetupApp(AppBuilder builder);
string FindGitExecutable();
string FindVSCode();
2024-03-27 22:49:32 -07:00
string FindFleet();
void OpenTerminal(string workdir);
void OpenInFileManager(string path, bool select);
void OpenBrowser(string url);
void OpenWithDefaultEditor(string file);
}
2024-03-27 22:49:32 -07:00
public static string GitInstallPath { get; set; }
2024-03-27 22:49:32 -07:00
public static string VSCodeExecutableFile { get; set; }
public static string FleetExecutableFile { get; set; }
static OS()
{
if (OperatingSystem.IsWindows())
{
_backend = new Windows();
}
else if (OperatingSystem.IsMacOS())
{
_backend = new MacOS();
}
else if (OperatingSystem.IsLinux())
{
_backend = new Linux();
}
else
{
throw new Exception("Platform unsupported!!!");
}
2024-03-27 22:49:32 -07:00
VSCodeExecutableFile = _backend.FindVSCode();
FleetExecutableFile = _backend.FindFleet();
}
public static void SetupApp(AppBuilder builder)
{
2024-03-28 02:48:46 -07:00
_backend.SetupApp(builder);
}
public static string FindGitExecutable()
{
2024-03-28 02:48:46 -07:00
return _backend.FindGitExecutable();
}
public static void OpenInFileManager(string path, bool select = false)
{
2024-03-28 02:48:46 -07:00
_backend.OpenInFileManager(path, select);
}
public static void OpenBrowser(string url)
{
2024-03-28 02:48:46 -07:00
_backend.OpenBrowser(url);
}
public static void OpenTerminal(string workdir)
{
2024-03-28 02:48:46 -07:00
_backend.OpenTerminal(workdir);
}
public static void OpenWithDefaultEditor(string file)
{
2024-03-28 02:48:46 -07:00
_backend.OpenWithDefaultEditor(file);
}
public static void OpenInVSCode(string repo)
{
if (string.IsNullOrEmpty(VSCodeExecutableFile))
{
App.RaiseException(repo, "Visual Studio Code can NOT be found in your system!!!");
return;
}
Process.Start(new ProcessStartInfo()
{
WorkingDirectory = repo,
FileName = VSCodeExecutableFile,
Arguments = $"\"{repo}\"",
UseShellExecute = false,
});
}
2024-03-27 22:49:32 -07:00
public static void OpenInFleet(string repo)
{
if (string.IsNullOrEmpty(FleetExecutableFile))
{
App.RaiseException(repo, "Fleet can NOT be found in your system!!!");
return;
}
Process.Start(new ProcessStartInfo()
{
WorkingDirectory = repo,
FileName = FleetExecutableFile,
Arguments = $"\"{repo}\"",
UseShellExecute = false,
2024-03-27 22:49:32 -07:00
});
}
private static readonly IBackend _backend;
}
}