2024-03-17 18:37:06 -07:00
|
|
|
|
using System;
|
2024-04-05 22:14:22 -07:00
|
|
|
|
using System.Collections.Generic;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
using Avalonia;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.Native
|
|
|
|
|
{
|
|
|
|
|
public static class OS
|
|
|
|
|
{
|
|
|
|
|
public interface IBackend
|
|
|
|
|
{
|
2024-03-14 03:23:36 -07:00
|
|
|
|
void SetupApp(AppBuilder builder);
|
2024-03-07 20:22:22 -08:00
|
|
|
|
|
2024-02-20 19:29:28 -08:00
|
|
|
|
string FindGitExecutable();
|
2024-04-08 02:39:52 -07:00
|
|
|
|
List<Models.ExternalTool> FindExternalTools();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
void OpenTerminal(string workdir);
|
|
|
|
|
void OpenInFileManager(string path, bool select);
|
|
|
|
|
void OpenBrowser(string url);
|
|
|
|
|
void OpenWithDefaultEditor(string file);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-05 22:14:22 -07:00
|
|
|
|
public static string GitExecutable { get; set; } = string.Empty;
|
2024-04-08 02:39:52 -07:00
|
|
|
|
public static List<Models.ExternalTool> ExternalTools { get; set; } = new List<Models.ExternalTool>();
|
2024-03-27 22:49:32 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
static OS()
|
|
|
|
|
{
|
2024-03-28 02:42:13 -07:00
|
|
|
|
if (OperatingSystem.IsWindows())
|
|
|
|
|
{
|
|
|
|
|
_backend = new Windows();
|
|
|
|
|
}
|
|
|
|
|
else if (OperatingSystem.IsMacOS())
|
|
|
|
|
{
|
|
|
|
|
_backend = new MacOS();
|
|
|
|
|
}
|
|
|
|
|
else if (OperatingSystem.IsLinux())
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-03-28 02:42:13 -07:00
|
|
|
|
_backend = new Linux();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Platform unsupported!!!");
|
|
|
|
|
}
|
2024-03-27 22:49:32 -07:00
|
|
|
|
|
2024-04-08 02:39:52 -07:00
|
|
|
|
ExternalTools = _backend.FindExternalTools();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-08 19:41:37 -07:00
|
|
|
|
public static Models.Shell GetShell()
|
|
|
|
|
{
|
|
|
|
|
if (OperatingSystem.IsWindows())
|
|
|
|
|
{
|
|
|
|
|
return (_backend as Windows).Shell;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Models.Shell.Default;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool SetShell(Models.Shell shell)
|
|
|
|
|
{
|
|
|
|
|
if (OperatingSystem.IsWindows())
|
|
|
|
|
{
|
|
|
|
|
var windows = (_backend as Windows);
|
|
|
|
|
if (windows.Shell != shell)
|
|
|
|
|
{
|
|
|
|
|
windows.Shell = shell;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void SetupApp(AppBuilder builder)
|
|
|
|
|
{
|
2024-03-28 02:48:46 -07:00
|
|
|
|
_backend.SetupApp(builder);
|
2024-03-07 20:22:22 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static string FindGitExecutable()
|
|
|
|
|
{
|
2024-03-28 02:48:46 -07:00
|
|
|
|
return _backend.FindGitExecutable();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void OpenInFileManager(string path, bool select = false)
|
|
|
|
|
{
|
2024-03-28 02:48:46 -07:00
|
|
|
|
_backend.OpenInFileManager(path, select);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void OpenBrowser(string url)
|
|
|
|
|
{
|
2024-03-28 02:48:46 -07:00
|
|
|
|
_backend.OpenBrowser(url);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void OpenTerminal(string workdir)
|
|
|
|
|
{
|
2024-03-28 02:48:46 -07:00
|
|
|
|
_backend.OpenTerminal(workdir);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void OpenWithDefaultEditor(string file)
|
|
|
|
|
{
|
2024-03-28 02:48:46 -07:00
|
|
|
|
_backend.OpenWithDefaultEditor(file);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-05 22:14:22 -07:00
|
|
|
|
private static IBackend _backend = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|