From 4659fbd9013c7a3380e0573490423badc1c9c740 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 28 Mar 2024 17:42:13 +0800 Subject: [PATCH] code_review: code review for PR #33 * use PNG instead of SVG for external tool icons and remove dependency `Avalonia.SVG` * remove unused property `IsVSCodeFound` and `IsFleetFound` * find VS from registry first * remove compile warning CA1416 * remove unused enum `OS.Platforms` --- src/SourceGit/Native/OS.cs | 45 ++++---- src/SourceGit/Native/Windows.cs | 12 ++- .../Resources/ExternalToolIcons/fleet.png | Bin 0 -> 5222 bytes .../ExternalToolIcons/fleet_icon.svg | 50 --------- .../Resources/ExternalToolIcons/vscode.png | Bin 0 -> 2564 bytes .../ExternalToolIcons/vscode_icon.svg | 13 --- src/SourceGit/SourceGit.csproj | 6 +- src/SourceGit/ViewModels/Repository.cs | 14 +-- src/SourceGit/Views/Repository.axaml | 98 +++++++++--------- src/SourceGit/Views/Repository.axaml.cs | 9 -- 10 files changed, 85 insertions(+), 162 deletions(-) create mode 100644 src/SourceGit/Resources/ExternalToolIcons/fleet.png delete mode 100644 src/SourceGit/Resources/ExternalToolIcons/fleet_icon.svg create mode 100644 src/SourceGit/Resources/ExternalToolIcons/vscode.png delete mode 100644 src/SourceGit/Resources/ExternalToolIcons/vscode_icon.svg diff --git a/src/SourceGit/Native/OS.cs b/src/SourceGit/Native/OS.cs index 7169d51f..2229ed18 100644 --- a/src/SourceGit/Native/OS.cs +++ b/src/SourceGit/Native/OS.cs @@ -3,8 +3,6 @@ using System.Diagnostics; using Avalonia; -// ReSharper disable InconsistentNaming - namespace SourceGit.Native { public static class OS @@ -29,27 +27,24 @@ namespace SourceGit.Native public static string FleetExecutableFile { get; set; } - public enum Platforms - { - 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() { - _backend = Platform switch + if (OperatingSystem.IsWindows()) { -#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!!!") - }; + _backend = new Windows(); + } + else if (OperatingSystem.IsMacOS()) + { + _backend = new MacOS(); + } + else if (OperatingSystem.IsLinux()) + { + _backend = new Linux(); + } + else + { + throw new Exception("Platform unsupported!!!"); + } VSCodeExecutableFile = _backend.FindVSCode(); FleetExecutableFile = _backend.FindFleet(); @@ -95,7 +90,10 @@ namespace SourceGit.Native Process.Start(new ProcessStartInfo() { - WorkingDirectory = repo, FileName = VSCodeExecutableFile, Arguments = $"\"{repo}\"", UseShellExecute = false, + WorkingDirectory = repo, + FileName = VSCodeExecutableFile, + Arguments = $"\"{repo}\"", + UseShellExecute = false, }); } @@ -111,7 +109,10 @@ namespace SourceGit.Native Process.Start(new ProcessStartInfo() { - WorkingDirectory = repo, FileName = FleetExecutableFile, Arguments = $"\"{repo}\"", UseShellExecute = false, + WorkingDirectory = repo, + FileName = FleetExecutableFile, + Arguments = $"\"{repo}\"", + UseShellExecute = false, }); } } diff --git a/src/SourceGit/Native/Windows.cs b/src/SourceGit/Native/Windows.cs index ead733f1..3e6443d9 100644 --- a/src/SourceGit/Native/Windows.cs +++ b/src/SourceGit/Native/Windows.cs @@ -103,11 +103,21 @@ namespace SourceGit.Native 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\{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"); diff --git a/src/SourceGit/Resources/ExternalToolIcons/fleet.png b/src/SourceGit/Resources/ExternalToolIcons/fleet.png new file mode 100644 index 0000000000000000000000000000000000000000..85e2fab0ce7c56e85aa424fb8d114c0f766f85b9 GIT binary patch literal 5222 zcmV-s6q)OZP)J3Pn(S58iwCy?5_D zKWFw{{bTQ$Gv~Yu?}C6}-XxQmGw0khXTI}Y-?i3v@40YjIkX&F4lR$~B9GTFu$ump^(R2ctoXMB~MB2AtX$zqQD?r9z zqX?3W85ASl@Ts@YfAI+g%sE$Cw;cCA8l1ib5fPn$F$+#;0#Y$15r_Z;BP4)Gz}OIE z#Gn}4YySSUh5vd&0CUb&c5E3&|6*z&zb+kiy9<0%B%Zh^(>1qTs<7 zz)+BZ!N7)EWUsmO)XslCu7Nr0>%)^m&cCYKVg-h31VSWzvm6*s6SgD}Y@#_9B0#|> zusoDw2qQs;hU>8^m*qa#jgriezS$OD066VlW`Bz>X5 znvejpGQMAq!H)!8HL{`HkLs^p@_U{Cdt3o?)|LG?lF6sVi4zB^P=P}QkVpc?4isQ( zB2%#@W~2yA0>#Iz_lY?L*g$ZrkPYqh}1&z9o)Dap0Ul)&Rs!La1Vo>a@1h8bc#=s!&RTTZ^zyuf5@Y z3@Zu7m7>c8nxAM(1x_dpDS=VIMnV_}ZYALNIc~b8&0H>Q?HF5I#+H_`MLk=@ z+gu*Ll1p*gtIpkg_ah3-S>G7^y0+zOlA+ECk|m~ODSWaBh-&<{N?RTb9Gd~C(v)U4 z3MqViNez$`2IBzZ2n;>Ltq99I;D+0}EH1)fUD(zRY|D&oF0h4?O_a+%59j{Q`I|nu zUSRaW-aOgNxm+$0MQfqeX;3tQQmxY1)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xNLEBW@E%R;2vA~-pRmZKe#dzs3q~t|vzT=<56d}A zx8<#Of8eIdpkB$bs5J;fwdK3o`9FO3cz4d{J}3TX_JrGd0UBLjp1-+2K4pF+M~5gZHDe@c zOf^Mg!kRR!Q3F%ik#WsK)DmZ~*U651+kARQtNs2@TqniP^a;0zv%Keb`!DLQy0bTo z!b|4HJOxm!`B3^~oCgy$SiO}X6O+k;?a$oKrQELB*K!~J%Nz1X^&$1g^q*dw_gnT0 zGA!QEE$ju|A{^T;?5I5Gd|uLV-dbXYhr+843zObZ!@YggJNs(aujcJfU;G`}$)V-Y ga%efU{2VO*4 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/SourceGit/Resources/ExternalToolIcons/vscode.png b/src/SourceGit/Resources/ExternalToolIcons/vscode.png new file mode 100644 index 0000000000000000000000000000000000000000..1ee79ae1b7378f7c0e097540a4c497fe3c6f0e93 GIT binary patch literal 2564 zcmV+f3j6hmP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D37JVmK~#8N?VEdS zQ`a5Gf9KxoXI|zxpq(gnlF|uS2Z3}zVW=yQq0ntqbo~RmRRvmx8XhBtNtG2;nm8n| zz@Sjn3MxSbsFcz`AnlsMc!ZE3ZDU1+gh59)+6G8sNbK16{`R}}NrdY>?0cQqk@k_C zd(QVd_PO74e&_z~@xAbW02tr)D@ML~`lpNuMFW#803dvW0Gm+~x1W9aad+_Dk}6FG0(%mSz zUin<=lTRo%2Xd)TiMt7A$MHo1u){PvS-I5b#MK0|qhdA9OuK=Q|?D9zd+?%T>xAJ=QtUPNm8=CjiXXkK5H@fo#gykV4Vf35l z2PIkMPdYI`WwFU8owb+Lrt^AKq^&I*U^2KXVrc*!!qov*^Xt5#nGO>k*;qT$C%|bM z9Fw^e21V}^;FD|93#*>vQbbtRRE+Q{66F9el}oyz3!+0F5GM{yvHp!qnhBVYQF!ig zQTCsuIcju3?FKrKRA9nEyQ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*{vwY(P60Zbprq;q zg@&C=nlTwf7?7kr!a5CyzG7t2`C$^mF$U}>T+&1=Ob82yzT!q+_AO>cH8d)@6gT2# zf=XTPlg(hU&7rvdfJ<>9t|q9|@u6Ja=f{cYd)Y0oO zB{A-3ZKpnOq7xPM;ST!SM=+UPPbd>q>eo%$Ml<#c^im(v=v62LPYoY@xjf-aP^n*= zeL!S5myC$&skVqgXhFoyl8?8XE7PC*>6obDU-4E^s;dg-)_{eObBoQ#fbqR~p9w06Z0e4GzKjfKQu(5 - - - - - \ No newline at end of file diff --git a/src/SourceGit/SourceGit.csproj b/src/SourceGit/SourceGit.csproj index 9dbaa5c5..8a1b5a45 100644 --- a/src/SourceGit/SourceGit.csproj +++ b/src/SourceGit/SourceGit.csproj @@ -23,6 +23,7 @@ + @@ -44,7 +45,6 @@ - @@ -58,8 +58,4 @@ - - - - diff --git a/src/SourceGit/ViewModels/Repository.cs b/src/SourceGit/ViewModels/Repository.cs index 76444e6e..f8c25987 100644 --- a/src/SourceGit/ViewModels/Repository.cs +++ b/src/SourceGit/ViewModels/Repository.cs @@ -49,18 +49,6 @@ namespace SourceGit.ViewModels set; } = new AvaloniaList(); - [JsonIgnore] - public bool IsVSCodeFound - { - get => !string.IsNullOrEmpty(Native.OS.VSCodeExecutableFile); - } - - [JsonIgnore] - public bool IsFleetFound - { - get => !string.IsNullOrEmpty(Native.OS.FleetExecutableFile); - } - [JsonIgnore] public Models.GitFlow GitFlow { @@ -291,7 +279,7 @@ namespace SourceGit.ViewModels { Native.OS.OpenInVSCode(_fullpath); } - + public void OpenInFleet() { Native.OS.OpenInFleet(_fullpath); diff --git a/src/SourceGit/Views/Repository.axaml b/src/SourceGit/Views/Repository.axaml index 5518279c..6632d5c7 100644 --- a/src/SourceGit/Views/Repository.axaml +++ b/src/SourceGit/Views/Repository.axaml @@ -18,33 +18,33 @@ - - - - + + + + + + @@ -83,7 +83,7 @@ - - @@ -230,22 +230,22 @@ - + - + - - @@ -301,10 +301,10 @@ - @@ -318,10 +318,10 @@ -