Merge branch 'feature/open_with' from PR #33

This commit is contained in:
leo 2024-03-28 17:42:55 +08:00
commit 7866a11037
13 changed files with 143 additions and 83 deletions

View file

@ -1,4 +1,5 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.Versioning;
@ -30,7 +31,15 @@ namespace SourceGit.Native
public string FindVSCode()
{
if (File.Exists("/usr/share/code/code")) return "/usr/share/code/code";
var toolPath = "/usr/share/code/code";
if (File.Exists(toolPath)) return toolPath;
return string.Empty;
}
public string FindFleet()
{
var toolPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/.local/share/JetBrains/Toolbox/apps/fleet/bin/Fleet";
if (File.Exists(toolPath)) return toolPath;
return string.Empty;
}

View file

@ -1,4 +1,5 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.Versioning;
using System.Text;
@ -27,11 +28,17 @@ namespace SourceGit.Native
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";
}
var toolPath = "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code";
if (File.Exists(toolPath))
return toolPath;
return string.Empty;
}
public string FindFleet()
{
var toolPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/Applications/Fleet.app/Contents/MacOS/Fleet";
if (File.Exists(toolPath))
return toolPath;
return string.Empty;
}

View file

@ -13,6 +13,7 @@ namespace SourceGit.Native
string FindGitExecutable();
string FindVSCode();
string FindFleet();
void OpenTerminal(string workdir);
void OpenInFileManager(string path, bool select);
@ -20,39 +21,33 @@ namespace SourceGit.Native
void OpenWithDefaultEditor(string file);
}
public static string GitInstallPath
{
get;
set;
}
public static string GitInstallPath { get; set; }
public static string VSCodeExecutableFile
{
get;
set;
}
public static string VSCodeExecutableFile { get; set; }
public static string FleetExecutableFile { get; set; }
static OS()
{
if (OperatingSystem.IsMacOS())
{
_backend = new MacOS();
VSCodeExecutableFile = _backend.FindVSCode();
}
else if (OperatingSystem.IsWindows())
if (OperatingSystem.IsWindows())
{
_backend = new Windows();
VSCodeExecutableFile = _backend.FindVSCode();
}
else if (OperatingSystem.IsMacOS())
{
_backend = new MacOS();
}
else if (OperatingSystem.IsLinux())
{
_backend = new Linux();
VSCodeExecutableFile = _backend.FindVSCode();
}
else
{
throw new Exception("Platform unsupported!!!");
}
VSCodeExecutableFile = _backend.FindVSCode();
FleetExecutableFile = _backend.FindFleet();
}
public static void SetupApp(AppBuilder builder)
@ -103,5 +98,22 @@ namespace SourceGit.Native
}
private static readonly IBackend _backend = null;
public static void OpenInFleet(string repo)
{
if (string.IsNullOrEmpty(FleetExecutableFile))
{
App.RaiseException(repo, "Fleet can NOT be found in your system!!!");
return;
}
Process.Start(new ProcessStartInfo()
{
WorkingDirectory = repo,
FileName = FleetExecutableFile,
Arguments = $"\"{repo}\"",
UseShellExecute = false,
});
}
}
}

View file

@ -116,30 +116,21 @@ namespace SourceGit.Native
Microsoft.Win32.RegistryHive.LocalMachine,
Environment.Is64BitOperatingSystem ? Microsoft.Win32.RegistryView.Registry64 : Microsoft.Win32.RegistryView.Registry32);
var vscode = root.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C26E74D1-022E-4238-8B9D-1E7564A36CC9}_is1");
var vscode = root.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{EA457B21-F73E-494C-ACAB-524FDE069978}_is1");
if (vscode != null)
{
return vscode.GetValue("DisplayIcon") as string;
}
vscode = root.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1287CAD5-7C8D-410D-88B9-0D1EE4A83FF2}_is1");
if (vscode != null)
{
return vscode.GetValue("DisplayIcon") as string;
}
vscode = root.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F8A2A208-72B3-4D61-95FC-8A65D340689B}_is1");
if (vscode != null)
{
return vscode.GetValue("DisplayIcon") as string;
}
vscode = root.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{EA457B21-F73E-494C-ACAB-524FDE069978}_is1");
if (vscode != null)
{
return vscode.GetValue("DisplayIcon") as string;
}
var toolPath = Environment.ExpandEnvironmentVariables($"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe");
if (File.Exists(toolPath)) return toolPath;
return string.Empty;
}
public string FindFleet()
{
var toolPath = Environment.ExpandEnvironmentVariables($"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\\AppData\\Local\\Programs\\Fleet\\Fleet.exe");
if (File.Exists(toolPath)) return toolPath;
return string.Empty;
}