2024-03-07 20:22:22 -08:00
|
|
|
|
using Avalonia;
|
|
|
|
|
using Avalonia.Media;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
namespace SourceGit.Native {
|
|
|
|
|
[SupportedOSPlatform("macOS")]
|
|
|
|
|
internal class MacOS : OS.IBackend {
|
2024-03-07 20:22:22 -08:00
|
|
|
|
public void SetupFonts(AppBuilder builder) {
|
|
|
|
|
builder.With(new FontManagerOptions() {
|
|
|
|
|
DefaultFamilyName = "PingFang SC",
|
|
|
|
|
FontFallbacks = [
|
|
|
|
|
new FontFallback { FontFamily = new FontFamily("PingFang SC") }
|
|
|
|
|
]
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-20 19:29:28 -08:00
|
|
|
|
public string FindGitExecutable() {
|
|
|
|
|
if (File.Exists("/usr/bin/git")) return "/usr/bin/git";
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string FindVSCode() {
|
|
|
|
|
if (File.Exists("/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code")) {
|
|
|
|
|
return "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OpenBrowser(string url) {
|
|
|
|
|
Process.Start("open", url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OpenInFileManager(string path, bool select) {
|
|
|
|
|
if (Directory.Exists(path)) {
|
|
|
|
|
Process.Start("open", path);
|
|
|
|
|
} 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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OpenWithDefaultEditor(string file) {
|
|
|
|
|
Process.Start("open", file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|