2024-03-27 23:58:55 -07:00
|
|
|
|
using System;
|
2024-04-05 22:14:22 -07:00
|
|
|
|
using System.Collections.Generic;
|
2024-03-27 23:58:55 -07:00
|
|
|
|
using System.Diagnostics;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Runtime.Versioning;
|
2024-02-18 04:17:44 -08:00
|
|
|
|
using System.Text;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
using Avalonia;
|
|
|
|
|
using Avalonia.Media;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.Native
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
[SupportedOSPlatform("macOS")]
|
2024-03-17 18:37:06 -07:00
|
|
|
|
internal class MacOS : OS.IBackend
|
|
|
|
|
{
|
|
|
|
|
public void SetupApp(AppBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
builder.With(new FontManagerOptions()
|
|
|
|
|
{
|
2024-03-07 20:22:22 -08:00
|
|
|
|
DefaultFamilyName = "PingFang SC",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string FindGitExecutable()
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (File.Exists("/usr/bin/git"))
|
|
|
|
|
return "/usr/bin/git";
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-05 22:14:22 -07:00
|
|
|
|
public List<Models.ExternalEditor> FindExternalEditors()
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-04-05 22:14:22 -07:00
|
|
|
|
var editors = new List<Models.ExternalEditor>();
|
2024-03-28 02:46:03 -07:00
|
|
|
|
|
2024-04-05 22:14:22 -07:00
|
|
|
|
var vscode = FindVSCode();
|
|
|
|
|
if (!string.IsNullOrEmpty(vscode) && File.Exists(vscode))
|
|
|
|
|
{
|
|
|
|
|
editors.Add(new Models.ExternalEditor
|
|
|
|
|
{
|
|
|
|
|
Name = "Visual Studio Code",
|
2024-04-06 00:01:07 -07:00
|
|
|
|
Icon = "vscode.png",
|
2024-04-05 22:14:22 -07:00
|
|
|
|
Executable = vscode,
|
|
|
|
|
OpenCmdArgs = "\"{0}\"",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var vscodeInsiders = FindVSCodeInsiders();
|
|
|
|
|
if (!string.IsNullOrEmpty(vscodeInsiders) && File.Exists(vscodeInsiders))
|
|
|
|
|
{
|
|
|
|
|
editors.Add(new Models.ExternalEditor
|
|
|
|
|
{
|
|
|
|
|
Name = "Visual Studio Code - Insiders",
|
2024-04-06 00:01:07 -07:00
|
|
|
|
Icon = "vscode_insiders.png",
|
2024-04-05 22:14:22 -07:00
|
|
|
|
Executable = vscodeInsiders,
|
|
|
|
|
OpenCmdArgs = "\"{0}\"",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var fleet = FindFleet();
|
|
|
|
|
if (!string.IsNullOrEmpty(fleet) && File.Exists(fleet))
|
|
|
|
|
{
|
|
|
|
|
editors.Add(new Models.ExternalEditor
|
|
|
|
|
{
|
|
|
|
|
Name = "JetBrains Fleet",
|
2024-04-06 00:01:07 -07:00
|
|
|
|
Icon = "fleet.png",
|
2024-04-05 22:14:22 -07:00
|
|
|
|
Executable = fleet,
|
|
|
|
|
OpenCmdArgs = "\"{0}\"",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return editors;
|
2024-03-27 22:49:32 -07:00
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void OpenBrowser(string url)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Process.Start("open", url);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void OpenInFileManager(string path, bool select)
|
|
|
|
|
{
|
|
|
|
|
if (Directory.Exists(path))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Process.Start("open", path);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else if (File.Exists(path))
|
|
|
|
|
{
|
2024-02-18 03:00:42 -08:00
|
|
|
|
Process.Start("open", $"\"{path}\" -R");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void OpenTerminal(string workdir)
|
|
|
|
|
{
|
2024-02-18 04:17:44 -08:00
|
|
|
|
var dir = string.IsNullOrEmpty(workdir) ? "~" : workdir;
|
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
|
builder.AppendLine("on run argv");
|
|
|
|
|
builder.AppendLine(" tell application \"Terminal\"");
|
|
|
|
|
builder.AppendLine($" do script \"cd '{dir}'\"");
|
|
|
|
|
builder.AppendLine(" activate");
|
|
|
|
|
builder.AppendLine(" end tell");
|
|
|
|
|
builder.AppendLine("end run");
|
|
|
|
|
|
|
|
|
|
var tmp = Path.GetTempFileName();
|
|
|
|
|
File.WriteAllText(tmp, builder.ToString());
|
|
|
|
|
|
|
|
|
|
var proc = Process.Start("/usr/bin/osascript", $"\"{tmp}\"");
|
|
|
|
|
proc.Exited += (o, e) => File.Delete(tmp);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void OpenWithDefaultEditor(string file)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Process.Start("open", file);
|
|
|
|
|
}
|
2024-04-05 22:14:22 -07:00
|
|
|
|
|
|
|
|
|
#region EXTERNAL_EDITORS_FINDER
|
|
|
|
|
private string FindVSCode()
|
|
|
|
|
{
|
|
|
|
|
var toolPath = "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code";
|
|
|
|
|
if (File.Exists(toolPath))
|
|
|
|
|
return toolPath;
|
|
|
|
|
|
|
|
|
|
var customPath = Environment.GetEnvironmentVariable("VSCODE_PATH");
|
|
|
|
|
if (!string.IsNullOrEmpty(customPath))
|
|
|
|
|
return customPath;
|
|
|
|
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string FindVSCodeInsiders()
|
|
|
|
|
{
|
|
|
|
|
var toolPath = "/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin/code";
|
|
|
|
|
if (File.Exists(toolPath))
|
|
|
|
|
return toolPath;
|
|
|
|
|
|
|
|
|
|
var customPath = Environment.GetEnvironmentVariable("VSCODE_INSIDERS_PATH");
|
|
|
|
|
if (!string.IsNullOrEmpty(customPath))
|
|
|
|
|
return customPath;
|
|
|
|
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string FindFleet()
|
|
|
|
|
{
|
|
|
|
|
var toolPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/Applications/Fleet.app/Contents/MacOS/Fleet";
|
|
|
|
|
if (File.Exists(toolPath))
|
|
|
|
|
return toolPath;
|
|
|
|
|
|
|
|
|
|
var customPath = Environment.GetEnvironmentVariable("FLEET_PATH");
|
|
|
|
|
if (!string.IsNullOrEmpty(customPath))
|
|
|
|
|
return customPath;
|
|
|
|
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|