From cde5fc8f7366c938ef12c4f9fb4231928111b588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enner=20P=C3=A9rez?= Date: Thu, 28 Mar 2024 00:49:32 -0500 Subject: [PATCH 1/3] Open In Fleet --- src/SourceGit/Native/Linux.cs | 7 ++ src/SourceGit/Native/MacOS.cs | 10 +++ src/SourceGit/Native/OS.cs | 71 +++++++++++-------- src/SourceGit/Native/Windows.cs | 37 +++------- .../ExternalToolIcons/fleet_icon.svg | 50 +++++++++++++ src/SourceGit/Resources/Locales.Designer.cs | 10 ++- src/SourceGit/Resources/Locales.en.resx | 3 + src/SourceGit/Resources/Locales.resx | 3 + src/SourceGit/SourceGit.csproj | 5 ++ src/SourceGit/ViewModels/Repository.cs | 11 +++ src/SourceGit/Views/Repository.axaml | 1 + 11 files changed, 149 insertions(+), 59 deletions(-) create mode 100644 src/SourceGit/Resources/ExternalToolIcons/fleet_icon.svg diff --git a/src/SourceGit/Native/Linux.cs b/src/SourceGit/Native/Linux.cs index a770abf56e..6aa2b50d2e 100644 --- a/src/SourceGit/Native/Linux.cs +++ b/src/SourceGit/Native/Linux.cs @@ -33,6 +33,13 @@ public string FindVSCode() if (File.Exists("/usr/share/code/code")) return "/usr/share/code/code"; return string.Empty; } + + public string FindFleet() + { + var path = "~/.local/share/JetBrains/Toolbox/apps/fleet/bin/Fleet"; + if (File.Exists(path)) return path; + return string.Empty; + } public void OpenBrowser(string url) { diff --git a/src/SourceGit/Native/MacOS.cs b/src/SourceGit/Native/MacOS.cs index b56ab1ff17..d0586a12f0 100644 --- a/src/SourceGit/Native/MacOS.cs +++ b/src/SourceGit/Native/MacOS.cs @@ -34,6 +34,16 @@ public string FindVSCode() return string.Empty; } + + public string FindFleet() + { + if (File.Exists("/Applications/Fleet.app/Contents/MacOS/Fleet")) + { + return "/Applications/Fleet.app/Contents/MacOS/Fleet"; + } + + return string.Empty; + } public void OpenBrowser(string url) { diff --git a/src/SourceGit/Native/OS.cs b/src/SourceGit/Native/OS.cs index 78f1297268..7169d51f9f 100644 --- a/src/SourceGit/Native/OS.cs +++ b/src/SourceGit/Native/OS.cs @@ -3,6 +3,8 @@ using Avalonia; +// ReSharper disable InconsistentNaming + namespace SourceGit.Native { public static class OS @@ -13,6 +15,7 @@ public interface IBackend string FindGitExecutable(); string FindVSCode(); + string FindFleet(); void OpenTerminal(string workdir); void OpenInFileManager(string path, bool select); @@ -20,39 +23,36 @@ public interface IBackend void OpenWithDefaultEditor(string file); } - public static string GitInstallPath - { - get; - set; - } + public static string GitInstallPath { get; set; } - public static string VSCodeExecutableFile + public static string VSCodeExecutableFile { get; set; } + + public static string FleetExecutableFile { get; set; } + + public enum Platforms { - get; - set; + Unknown = 0, + Windows = 1, + MacOS = 2, + Linux } + public static Platforms Platform => OperatingSystem.IsWindows() ? Platforms.Windows : OperatingSystem.IsMacOS() ? Platforms.MacOS : OperatingSystem.IsLinux() ? Platforms.Linux : Platforms.Unknown; + static OS() { - if (OperatingSystem.IsMacOS()) - { - _backend = new MacOS(); - VSCodeExecutableFile = _backend.FindVSCode(); - } - else if (OperatingSystem.IsWindows()) - { - _backend = new Windows(); - VSCodeExecutableFile = _backend.FindVSCode(); - } - else if (OperatingSystem.IsLinux()) - { - _backend = new Linux(); - VSCodeExecutableFile = _backend.FindVSCode(); - } - else + _backend = Platform switch { - throw new Exception("Platform unsupported!!!"); - } +#pragma warning disable CA1416 + Platforms.Windows => new Windows(), + Platforms.MacOS => new MacOS(), + Platforms.Linux => new Linux(), +#pragma warning restore CA1416 + _ => throw new Exception("Platform unsupported!!!") + }; + + VSCodeExecutableFile = _backend.FindVSCode(); + FleetExecutableFile = _backend.FindFleet(); } public static void SetupApp(AppBuilder builder) @@ -95,13 +95,24 @@ public static void OpenInVSCode(string repo) Process.Start(new ProcessStartInfo() { - WorkingDirectory = repo, - FileName = VSCodeExecutableFile, - Arguments = $"\"{repo}\"", - UseShellExecute = false, + WorkingDirectory = repo, FileName = VSCodeExecutableFile, Arguments = $"\"{repo}\"", UseShellExecute = false, }); } 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, + }); + } } } \ No newline at end of file diff --git a/src/SourceGit/Native/Windows.cs b/src/SourceGit/Native/Windows.cs index 14f04aecc6..b958acca33 100644 --- a/src/SourceGit/Native/Windows.cs +++ b/src/SourceGit/Native/Windows.cs @@ -103,34 +103,15 @@ public string FindGitExecutable() public string FindVSCode() { - var root = Microsoft.Win32.RegistryKey.OpenBaseKey( - 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"); - 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 vscodePath = Environment.ExpandEnvironmentVariables("%USERPROFILE%\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"); + if (File.Exists(vscodePath)) return vscodePath; + return string.Empty; + } + + public string FindFleet() + { + var vscodePath = Environment.ExpandEnvironmentVariables("%USERPROFILE%\\AppData\\Local\\Programs\\Fleet\\Fleet.exe"); + if (File.Exists(vscodePath)) return vscodePath; return string.Empty; } diff --git a/src/SourceGit/Resources/ExternalToolIcons/fleet_icon.svg b/src/SourceGit/Resources/ExternalToolIcons/fleet_icon.svg new file mode 100644 index 0000000000..3ab51b6e70 --- /dev/null +++ b/src/SourceGit/Resources/ExternalToolIcons/fleet_icon.svg @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/SourceGit/Resources/Locales.Designer.cs b/src/SourceGit/Resources/Locales.Designer.cs index ba49250436..4419d3efc0 100644 --- a/src/SourceGit/Resources/Locales.Designer.cs +++ b/src/SourceGit/Resources/Locales.Designer.cs @@ -1,7 +1,6 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -2967,6 +2966,15 @@ public static string Text_Repository_Explore { } } + /// + /// Looks up a localized string similar to Open In Fleet. + /// + public static string Text_Repository_Fleet { + get { + return ResourceManager.GetString("Text.Repository.Fleet", resourceCulture); + } + } + /// /// Looks up a localized string similar to LOCAL BRANCHES. /// diff --git a/src/SourceGit/Resources/Locales.en.resx b/src/SourceGit/Resources/Locales.en.resx index 2f9e7bdd1e..d1a5161265 100644 --- a/src/SourceGit/Resources/Locales.en.resx +++ b/src/SourceGit/Resources/Locales.en.resx @@ -342,6 +342,9 @@ Open In Visual Studio Code + + Open In Fleet + Open In Git Bash diff --git a/src/SourceGit/Resources/Locales.resx b/src/SourceGit/Resources/Locales.resx index 8e06cd4d82..22caa86ba6 100644 --- a/src/SourceGit/Resources/Locales.resx +++ b/src/SourceGit/Resources/Locales.resx @@ -342,6 +342,9 @@ Open In Visual Studio Code + + Open In Fleet + Open In Git Bash diff --git a/src/SourceGit/SourceGit.csproj b/src/SourceGit/SourceGit.csproj index 0edbbb2fda..9dbaa5c540 100644 --- a/src/SourceGit/SourceGit.csproj +++ b/src/SourceGit/SourceGit.csproj @@ -44,6 +44,7 @@ + @@ -57,4 +58,8 @@ + + + + diff --git a/src/SourceGit/ViewModels/Repository.cs b/src/SourceGit/ViewModels/Repository.cs index ee684ee37e..76444e6e95 100644 --- a/src/SourceGit/ViewModels/Repository.cs +++ b/src/SourceGit/ViewModels/Repository.cs @@ -54,6 +54,12 @@ public bool IsVSCodeFound { get => !string.IsNullOrEmpty(Native.OS.VSCodeExecutableFile); } + + [JsonIgnore] + public bool IsFleetFound + { + get => !string.IsNullOrEmpty(Native.OS.FleetExecutableFile); + } [JsonIgnore] public Models.GitFlow GitFlow @@ -285,6 +291,11 @@ public void OpenInVSCode() { Native.OS.OpenInVSCode(_fullpath); } + + public void OpenInFleet() + { + Native.OS.OpenInFleet(_fullpath); + } public void OpenInTerminal() { diff --git a/src/SourceGit/Views/Repository.axaml b/src/SourceGit/Views/Repository.axaml index 9759ba008e..df76584223 100644 --- a/src/SourceGit/Views/Repository.axaml +++ b/src/SourceGit/Views/Repository.axaml @@ -21,6 +21,7 @@ + - - - - - - + + + + + diff --git a/src/SourceGit/Views/Repository.axaml.cs b/src/SourceGit/Views/Repository.axaml.cs index a5b33da758..ba0f271ae9 100644 --- a/src/SourceGit/Views/Repository.axaml.cs +++ b/src/SourceGit/Views/Repository.axaml.cs @@ -291,5 +291,14 @@ private async void OpenStatistics(object sender, RoutedEventArgs e) e.Handled = true; } } + + private void OpenInVSCode(object sender, RoutedEventArgs e) + { + (DataContext as ViewModels.Repository).OpenInVSCode(); + } + private void OpenInFleet(object sender, RoutedEventArgs e) + { + (DataContext as ViewModels.Repository).OpenInFleet(); + } } } \ No newline at end of file From 370b9bd31e0ece80ac9dfb99564984fb81d48158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enner=20Pe=CC=81rez?= Date: Thu, 28 Mar 2024 01:58:55 -0500 Subject: [PATCH 3/3] MacOS Update --- src/SourceGit/Native/MacOS.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/SourceGit/Native/MacOS.cs b/src/SourceGit/Native/MacOS.cs index d0586a12f0..006f7e8ebf 100644 --- a/src/SourceGit/Native/MacOS.cs +++ b/src/SourceGit/Native/MacOS.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; using System.IO; using System.Runtime.Versioning; using System.Text; @@ -27,21 +28,17 @@ public string FindGitExecutable() 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() { - if (File.Exists("/Applications/Fleet.app/Contents/MacOS/Fleet")) - { - return "/Applications/Fleet.app/Contents/MacOS/Fleet"; - } - + var toolPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/Applications/Fleet.app/Contents/MacOS/Fleet"; + if (File.Exists(toolPath)) + return toolPath; return string.Empty; }