2024-03-07 20:22:22 -08:00
|
|
|
|
using Avalonia;
|
|
|
|
|
using System;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
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-02-05 23:08:37 -08:00
|
|
|
|
string FindVSCode();
|
|
|
|
|
|
|
|
|
|
void OpenTerminal(string workdir);
|
|
|
|
|
void OpenInFileManager(string path, bool select);
|
|
|
|
|
void OpenBrowser(string url);
|
|
|
|
|
void OpenWithDefaultEditor(string file);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-20 19:29:28 -08:00
|
|
|
|
public static string GitInstallPath {
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string VSCodeExecutableFile {
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static OS() {
|
|
|
|
|
if (OperatingSystem.IsMacOS()) {
|
|
|
|
|
_backend = new MacOS();
|
|
|
|
|
VSCodeExecutableFile = _backend.FindVSCode();
|
|
|
|
|
} else if (OperatingSystem.IsWindows()) {
|
|
|
|
|
_backend = new Windows();
|
|
|
|
|
VSCodeExecutableFile = _backend.FindVSCode();
|
2024-02-21 20:26:01 -08:00
|
|
|
|
} else if (OperatingSystem.IsLinux()) {
|
|
|
|
|
_backend = new Linux();
|
|
|
|
|
VSCodeExecutableFile = _backend.FindVSCode();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
} else {
|
|
|
|
|
throw new Exception("Platform unsupported!!!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-14 03:23:36 -07:00
|
|
|
|
public static void SetupApp(AppBuilder builder) {
|
|
|
|
|
_backend?.SetupApp(builder);
|
2024-03-07 20:22:22 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-20 19:29:28 -08:00
|
|
|
|
public static string FindGitExecutable() {
|
|
|
|
|
return _backend?.FindGitExecutable();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void OpenInFileManager(string path, bool select = false) {
|
|
|
|
|
_backend?.OpenInFileManager(path, select);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void OpenBrowser(string url) {
|
|
|
|
|
_backend?.OpenBrowser(url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void OpenTerminal(string workdir) {
|
|
|
|
|
_backend?.OpenTerminal(workdir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void OpenWithDefaultEditor(string file) {
|
|
|
|
|
_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,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IBackend _backend = null;
|
|
|
|
|
}
|
|
|
|
|
}
|