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-08 02:39:52 -07:00
|
|
|
|
public List<Models.ExternalTool> FindExternalTools()
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-04-08 02:39:52 -07:00
|
|
|
|
var finder = new Models.ExternalToolsFinder();
|
2024-04-07 02:56:53 -07:00
|
|
|
|
finder.VSCode(() => "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code");
|
|
|
|
|
finder.VSCodeInsiders(() => "/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin/code");
|
|
|
|
|
finder.Fleet(() => $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/Applications/Fleet.app/Contents/MacOS/Fleet");
|
|
|
|
|
finder.SublimeText(() => "/Applications/Sublime Text.app/Contents/SharedSupport/bin");
|
2024-04-08 02:39:52 -07:00
|
|
|
|
return finder.Founded;
|
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-03-31 01:54:29 -07:00
|
|
|
|
}
|