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-05-04 22:01:04 -07:00
|
|
|
|
|
|
|
|
|
builder.With(new MacOSPlatformOptions()
|
|
|
|
|
{
|
|
|
|
|
DisableDefaultApplicationMenuItems = true,
|
|
|
|
|
});
|
2024-03-07 20:22:22 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string FindGitExecutable()
|
|
|
|
|
{
|
2024-04-15 02:48:52 -07:00
|
|
|
|
// XCode built-in git
|
|
|
|
|
return File.Exists("/usr/bin/git") ? "/usr/bin/git" : string.Empty;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
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");
|
2024-05-03 06:54:10 -07:00
|
|
|
|
finder.VSCodium(() => "/Applications/VSCodium.app/Contents/Resources/app/bin/codium");
|
2024-04-07 02:56:53 -07:00
|
|
|
|
finder.Fleet(() => $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/Applications/Fleet.app/Contents/MacOS/Fleet");
|
2024-04-27 00:12:03 -07:00
|
|
|
|
finder.FindJetBrainsFromToolbox(() => $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/Library/Application Support/JetBrains/Toolbox");
|
2024-04-15 02:48:52 -07:00
|
|
|
|
finder.SublimeText(() => "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl");
|
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;
|
2024-05-04 22:11:47 -07:00
|
|
|
|
dir = dir.Replace(" ", "\\ ");
|
|
|
|
|
|
2024-02-18 04:17:44 -08:00
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
|
builder.AppendLine("on run argv");
|
|
|
|
|
builder.AppendLine(" tell application \"Terminal\"");
|
2024-05-04 22:11:47 -07:00
|
|
|
|
builder.AppendLine($" do script \"cd {dir}\"");
|
2024-02-18 04:17:44 -08:00
|
|
|
|
builder.AppendLine(" activate");
|
|
|
|
|
builder.AppendLine(" end tell");
|
|
|
|
|
builder.AppendLine("end run");
|
|
|
|
|
|
|
|
|
|
var tmp = Path.GetTempFileName();
|
|
|
|
|
File.WriteAllText(tmp, builder.ToString());
|
|
|
|
|
|
2024-04-15 02:48:52 -07:00
|
|
|
|
var proc = Process.Start("osascript", $"\"{tmp}\"");
|
2024-07-14 09:30:31 -07:00
|
|
|
|
if (proc != null)
|
|
|
|
|
proc.Exited += (_, _) => File.Delete(tmp);
|
|
|
|
|
else
|
|
|
|
|
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
|
|
|
|
}
|