mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-23 10:22:13 +08:00
105 lines
3.7 KiB
C#
105 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Runtime.Versioning;
|
|
using System.Text;
|
|
|
|
using Avalonia;
|
|
|
|
namespace SourceGit.Native
|
|
{
|
|
[SupportedOSPlatform("macOS")]
|
|
internal class MacOS : OS.IBackend
|
|
{
|
|
public void SetupApp(AppBuilder builder)
|
|
{
|
|
builder.With(new MacOSPlatformOptions()
|
|
{
|
|
DisableDefaultApplicationMenuItems = true,
|
|
});
|
|
|
|
{
|
|
var startInfo = new ProcessStartInfo();
|
|
startInfo.FileName = "zsh";
|
|
startInfo.Arguments = "--login -c \"echo $PATH\"";
|
|
startInfo.UseShellExecute = false;
|
|
startInfo.CreateNoWindow = true;
|
|
startInfo.RedirectStandardOutput = true;
|
|
startInfo.StandardOutputEncoding = Encoding.UTF8;
|
|
|
|
try
|
|
{
|
|
var proc = new Process() { StartInfo = startInfo };
|
|
proc.Start();
|
|
var pathData = proc.StandardOutput.ReadToEnd();
|
|
proc.WaitForExit();
|
|
if (proc.ExitCode == 0)
|
|
Environment.SetEnvironmentVariable("PATH", pathData);
|
|
proc.Close();
|
|
}
|
|
catch
|
|
{
|
|
// Ignore error.
|
|
}
|
|
}
|
|
}
|
|
|
|
public string FindGitExecutable()
|
|
{
|
|
return File.Exists("/usr/bin/git") ? "/usr/bin/git" : string.Empty;
|
|
}
|
|
|
|
public string FindTerminal(Models.ShellOrTerminal shell)
|
|
{
|
|
switch (shell.Type)
|
|
{
|
|
case "mac-terminal":
|
|
return "Terminal";
|
|
case "iterm2":
|
|
return "iTerm";
|
|
}
|
|
|
|
return string.Empty;
|
|
}
|
|
|
|
public List<Models.ExternalTool> FindExternalTools()
|
|
{
|
|
var finder = new Models.ExternalToolsFinder();
|
|
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.VSCodium(() => "/Applications/VSCodium.app/Contents/Resources/app/bin/codium");
|
|
finder.Fleet(() => $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/Applications/Fleet.app/Contents/MacOS/Fleet");
|
|
finder.FindJetBrainsFromToolbox(() => $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/Library/Application Support/JetBrains/Toolbox");
|
|
finder.SublimeText(() => "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl");
|
|
finder.Zed(() => File.Exists("/usr/local/bin/zed") ? "/usr/local/bin/zed" : "/Applications/Zed.app/Contents/MacOS/cli");
|
|
return finder.Founded;
|
|
}
|
|
|
|
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))
|
|
Process.Start("open", $"\"{path}\" -R");
|
|
}
|
|
|
|
public void OpenTerminal(string workdir)
|
|
{
|
|
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
|
var dir = string.IsNullOrEmpty(workdir) ? home : workdir;
|
|
Process.Start("open", $"-a {OS.ShellOrTerminal} \"{dir}\"");
|
|
}
|
|
|
|
public void OpenWithDefaultEditor(string file)
|
|
{
|
|
Process.Start("open", $"\"{file}\"");
|
|
}
|
|
}
|
|
}
|