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`
This commit is contained in:
leo 2024-03-28 17:42:13 +08:00
parent 370b9bd31e
commit 4659fbd901
10 changed files with 85 additions and 162 deletions

View file

@ -3,8 +3,6 @@ using System.Diagnostics;
using Avalonia; using Avalonia;
// ReSharper disable InconsistentNaming
namespace SourceGit.Native namespace SourceGit.Native
{ {
public static class OS public static class OS
@ -29,27 +27,24 @@ namespace SourceGit.Native
public static string FleetExecutableFile { get; set; } 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() static OS()
{ {
_backend = Platform switch if (OperatingSystem.IsWindows())
{ {
#pragma warning disable CA1416 _backend = new Windows();
Platforms.Windows => new Windows(), }
Platforms.MacOS => new MacOS(), else if (OperatingSystem.IsMacOS())
Platforms.Linux => new Linux(), {
#pragma warning restore CA1416 _backend = new MacOS();
_ => throw new Exception("Platform unsupported!!!") }
}; else if (OperatingSystem.IsLinux())
{
_backend = new Linux();
}
else
{
throw new Exception("Platform unsupported!!!");
}
VSCodeExecutableFile = _backend.FindVSCode(); VSCodeExecutableFile = _backend.FindVSCode();
FleetExecutableFile = _backend.FindFleet(); FleetExecutableFile = _backend.FindFleet();
@ -95,7 +90,10 @@ namespace SourceGit.Native
Process.Start(new ProcessStartInfo() 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() Process.Start(new ProcessStartInfo()
{ {
WorkingDirectory = repo, FileName = FleetExecutableFile, Arguments = $"\"{repo}\"", UseShellExecute = false, WorkingDirectory = repo,
FileName = FleetExecutableFile,
Arguments = $"\"{repo}\"",
UseShellExecute = false,
}); });
} }
} }

View file

@ -103,6 +103,16 @@ namespace SourceGit.Native
public string FindVSCode() 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"); var toolPath = Environment.ExpandEnvironmentVariables($"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe");
if (File.Exists(toolPath)) return toolPath; if (File.Exists(toolPath)) return toolPath;
return string.Empty; return string.Empty;

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

View file

@ -1,50 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="70" height="70" fill="none" viewBox="0 0 70 70">
<defs>
<radialGradient id="a" cx="0" cy="0" r="1" gradientTransform="matrix(22.35433 -20.58122 27.17129 29.51214 38.648 42.538)" gradientUnits="userSpaceOnUse">
<stop offset=".771" stop-color="#001AFF"/>
<stop offset="1" stop-color="#8ACEFF"/>
</radialGradient>
<radialGradient id="b" cx="0" cy="0" r="1" gradientTransform="rotate(-30.543 79.837 -70.068) scale(16.777 22.1489)" gradientUnits="userSpaceOnUse">
<stop offset=".719" stop-color="#FA00FF" stop-opacity="0"/>
<stop offset="1" stop-color="#FF00D6" stop-opacity=".44"/>
</radialGradient>
<radialGradient id="c" cx="0" cy="0" r="1" gradientTransform="rotate(49.385 -19.814 41.858) scale(47.8852)" gradientUnits="userSpaceOnUse">
<stop offset=".026" stop-color="#8DFDFD"/>
<stop offset=".271" stop-color="#87FBFB"/>
<stop offset=".484" stop-color="#74D6F4"/>
<stop offset=".932" stop-color="#0038FF"/>
</radialGradient>
<radialGradient id="d" cx="0" cy="0" r="1" gradientTransform="rotate(137.237 9.434 23.195) scale(32.8316)" gradientUnits="userSpaceOnUse">
<stop offset=".267" stop-color="#0500FF" stop-opacity="0"/>
<stop offset="1" stop-color="#0500FF" stop-opacity=".15"/>
</radialGradient>
<radialGradient id="e" cx="0" cy="0" r="1" gradientTransform="rotate(75.198 -4.629 32.631) scale(51.1484)" gradientUnits="userSpaceOnUse">
<stop offset=".42" stop-color="#FF00E5" stop-opacity="0"/>
<stop offset=".774" stop-color="#FF00F5" stop-opacity=".64"/>
<stop offset=".899" stop-color="#BE46FF" stop-opacity=".87"/>
</radialGradient>
<radialGradient id="g" cx="0" cy="0" r="1" gradientTransform="matrix(2.73484 22.75837 -34.39872 4.13365 29.458 35.276)" gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="#00B2FF"/>
<stop offset=".571" stop-color="#74C5FF"/>
<stop offset=".979" stop-color="#9FD7FF"/>
</radialGradient>
<linearGradient id="f" x1="11.644" x2="82.363" y1="42.432" y2="43.401" gradientUnits="userSpaceOnUse">
<stop offset=".432" stop-color="#FE62EE" stop-opacity="0"/>
<stop offset=".818" stop-color="#FD3AF5" stop-opacity=".47"/>
</linearGradient>
<linearGradient id="h" x1="33.054" x2="37.35" y1="23.191" y2="49.344" gradientUnits="userSpaceOnUse">
<stop offset=".042" stop-color="#0038FF"/>
<stop offset=".724" stop-color="#48BFF1" stop-opacity=".59"/>
<stop offset="1" stop-color="#74C5FF" stop-opacity="0"/>
</linearGradient>
</defs>
<path fill="url(#a)" d="M65.153 30.85c0 9.496-10.163 17.194-22.7 17.194-12.536 0-22.699-7.698-22.699-17.194 0-9.496 10.163-17.194 22.7-17.194 12.536 0 22.699 7.698 22.699 17.194z"/>
<path fill="url(#b)" d="M65.153 30.85c0 9.496-10.163 17.194-22.7 17.194-12.536 0-22.699-7.698-22.699-17.194 0-9.496 10.163-17.194 22.7-17.194 12.536 0 22.699 7.698 22.699 17.194z"/>
<path fill="url(#c)" d="M66 35c0 17.12-13.88 31-31 31C17.88 66 4 52.12 4 35 4 17.88 17.88 4 35 4c8.046 3.642 16.464 17.194 19.99 21.429 3.524 4.235 12.648 9.571 8.176-1.623C65.073 26.832 66 31.852 66 35z"/>
<path fill="url(#d)" d="M66 35c0 17.12-13.88 31-31 31C17.88 66 4 52.12 4 35 4 17.88 17.88 4 35 4c8.046 3.642 16.464 17.194 19.99 21.429 3.524 4.235 12.648 9.571 8.176-1.623C65.073 26.832 66 31.852 66 35z"/>
<path fill="url(#e)" d="M66 35c0 17.12-13.88 31-31 31C17.88 66 4 52.12 4 35 4 17.88 17.88 4 35 4c8.046 3.642 16.464 17.194 19.99 21.429 3.524 4.235 12.648 9.571 8.176-1.623C65.073 26.832 66 31.852 66 35z"/>
<path fill="url(#f)" d="M66 35c0 17.12-13.88 31-31 31C17.88 66 4 52.12 4 35 4 17.88 17.88 4 35 4c8.046 3.642 16.464 17.194 19.99 21.429 3.524 4.235 12.648 9.571 8.176-1.623C65.073 26.832 66 31.852 66 35z"/>
<path fill="url(#g)" d="M56.651 39.682c1.658 7.764-6.511 16.089-18.246 18.594-11.734 2.505-22.59-1.757-24.248-9.52-1.658-7.764 6.511-16.089 18.246-18.594 11.734-2.506 22.59 1.757 24.248 9.52z"/>
<path fill="url(#h)" d="M56.651 39.682c1.658 7.764-6.511 16.089-18.246 18.594-11.734 2.505-22.59-1.757-24.248-9.52-1.658-7.764 6.511-16.089 18.246-18.594 11.734-2.506 22.59 1.757 24.248 9.52z"/>
<path fill="#D6F8F8" fill-opacity=".19" fill-rule="evenodd" d="M51.462 49.883c3.074-3.133 4.386-6.66 3.698-9.882-.688-3.223-3.326-5.907-7.411-7.51-4.073-1.6-9.412-2.037-15.028-.838-5.616 1.199-10.31 3.779-13.375 6.901-3.074 3.133-4.386 6.66-3.698 9.883.688 3.223 3.326 5.906 7.412 7.51 4.072 1.6 9.41 2.037 15.027.838 5.616-1.2 10.31-3.779 13.375-6.902zm-13.057 8.393c11.735-2.505 19.904-10.83 18.246-18.594-1.658-7.763-12.514-12.026-24.248-9.52-11.735 2.505-19.904 10.83-18.246 18.593 1.658 7.764 12.514 12.026 24.248 9.521z" clip-rule="evenodd"/>
</svg>

Before

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View file

@ -1,13 +0,0 @@
<svg height="2455"
viewBox="-11.9 -2 1003.9 995.6"
width="2500"
xmlns="http://www.w3.org/2000/svg">
<path d="m12.1 353.9s-24-17.3 4.8-40.4l67.1-60s19.2-20.2 39.5-2.6l619.2 468.8v224.8s-.3 35.3-45.6 31.4z"
fill="#2489ca"/>
<path d="m171.7 498.8-159.6 145.1s-16.4 12.2 0 34l74.1 67.4s17.6 18.9 43.6-2.6l169.2-128.3z"
fill="#1070b3"/>
<path d="m451.9 500 292.7-223.5-1.9-223.6s-12.5-48.8-54.2-23.4l-389.5 354.5z"
fill="#0877b9"/>
<path d="m697.1 976.2c17 17.4 37.6 11.7 37.6 11.7l228.1-112.4c29.2-19.9 25.1-44.6 25.1-44.6v-671.2c0-29.5-30.2-39.7-30.2-39.7l-197.7-95.3c-43.2-26.7-71.5 4.8-71.5 4.8s36.4-26.2 54.2 23.4v887.5c0 6.1-1.3 12.1-3.9 17.5-5.2 10.5-16.5 20.3-43.6 16.2z"
fill="#3c99d4"/>
</svg>

Before

Width:  |  Height:  |  Size: 769 B

View file

@ -23,6 +23,7 @@
<ItemGroup> <ItemGroup>
<AvaloniaResource Include="App.ico" /> <AvaloniaResource Include="App.ico" />
<AvaloniaResource Include="Resources/Fonts/*" /> <AvaloniaResource Include="Resources/Fonts/*" />
<AvaloniaResource Include="Resources/ExternalToolIcons/*" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -44,7 +45,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.10" /> <PackageReference Include="Avalonia" Version="11.0.10" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.10" /> <PackageReference Include="Avalonia.Desktop" Version="11.0.10" />
<PackageReference Include="Avalonia.Svg" Version="11.0.0.16" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.10" /> <PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.10" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.10" /> <PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.10" />
<PackageReference Include="Avalonia.AvaloniaEdit" Version="11.0.6" /> <PackageReference Include="Avalonia.AvaloniaEdit" Version="11.0.6" />
@ -58,8 +58,4 @@
<TrimmerRootAssembly Include="SourceGit" /> <TrimmerRootAssembly Include="SourceGit" />
<TrimmerRootAssembly Include="Avalonia.Themes.Fluent" /> <TrimmerRootAssembly Include="Avalonia.Themes.Fluent" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<AvaloniaResource Include="Resources\ExternalToolIcons\*" />
</ItemGroup>
</Project> </Project>

View file

@ -49,18 +49,6 @@ namespace SourceGit.ViewModels
set; set;
} = new AvaloniaList<string>(); } = new AvaloniaList<string>();
[JsonIgnore]
public bool IsVSCodeFound
{
get => !string.IsNullOrEmpty(Native.OS.VSCodeExecutableFile);
}
[JsonIgnore]
public bool IsFleetFound
{
get => !string.IsNullOrEmpty(Native.OS.FleetExecutableFile);
}
[JsonIgnore] [JsonIgnore]
public Models.GitFlow GitFlow public Models.GitFlow GitFlow
{ {

View file

@ -25,14 +25,14 @@
<Path Width="13" Height="13" Data="{StaticResource Icons.OpenWith}"/> <Path Width="13" Height="13" Data="{StaticResource Icons.OpenWith}"/>
<Button.Flyout> <Button.Flyout>
<MenuFlyout Placement="BottomEdgeAlignedLeft" VerticalOffset="-8"> <MenuFlyout Placement="BottomEdgeAlignedLeft" VerticalOffset="-8">
<MenuItem Header="{DynamicResource Text.Repository.Fleet}" Click="OpenInFleet"> <MenuItem Header="{DynamicResource Text.Repository.Fleet}" Command="{Binding OpenInFleet}">
<MenuItem.Icon> <MenuItem.Icon>
<Svg Path="/Resources/ExternalToolIcons/fleet_icon.svg" Width="13" Height="13" /> <Image Source="/Resources/ExternalToolIcons/fleet.png" Width="13" Height="13" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<MenuItem Header="{DynamicResource Text.Repository.VSCode}" Click="OpenInVSCode"> <MenuItem Header="{DynamicResource Text.Repository.VSCode}" Command="{Binding OpenInVSCode}">
<MenuItem.Icon> <MenuItem.Icon>
<Svg Path="/Resources/ExternalToolIcons/vscode_icon.svg" Width="13" Height="13" /> <Image Source="/Resources/ExternalToolIcons/vscode.png" Width="13" Height="13" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
</MenuFlyout> </MenuFlyout>

View file

@ -291,14 +291,5 @@ namespace SourceGit.Views
e.Handled = true; 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();
}
} }
} }