Skip to content

Commit a976f00

Browse files
committed
refactor: load external tool's icon on startup
1 parent 0da067c commit a976f00

File tree

3 files changed

+25
-43
lines changed

3 files changed

+25
-43
lines changed

src/App.axaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ public override void OnFrameworkInitializationCompleted()
266266
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
267267
{
268268
BindingPlugins.DataValidators.RemoveAt(0);
269+
Native.OS.SetupEnternalTools();
269270

270271
var launcher = new Views.Launcher();
271272
_notificationReceiver = launcher;

src/Models/ExternalTool.cs

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,23 @@ namespace SourceGit.Models
1212
{
1313
public class ExternalTool
1414
{
15-
public string Name { get; set; } = string.Empty;
16-
public string Icon { get; set; } = string.Empty;
17-
public string Executable { get; set; } = string.Empty;
18-
public string OpenCmdArgs { get; set; } = string.Empty;
15+
public string Name { get; private set; } = string.Empty;
16+
public string Executable { get; private set; } = string.Empty;
17+
public string OpenCmdArgs { get; private set; } = string.Empty;
18+
public Bitmap IconImage { get; private set; } = null;
1919

20-
public Bitmap IconImage
20+
public ExternalTool(string name, string icon, string executable, string openCmdArgs)
2121
{
22-
get
23-
{
24-
if (_isFirstTimeGetIcon)
25-
{
26-
_isFirstTimeGetIcon = false;
27-
28-
if (!string.IsNullOrWhiteSpace(Icon))
29-
{
30-
try
31-
{
32-
var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/ExternalToolIcons/{Icon}.png", UriKind.RelativeOrAbsolute));
33-
_iconImage = new Bitmap(icon);
34-
}
35-
catch
36-
{
37-
}
38-
}
39-
}
22+
Name = name;
23+
Executable = executable;
24+
OpenCmdArgs = openCmdArgs;
4025

41-
return _iconImage;
26+
try
27+
{
28+
var asset = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/ExternalToolIcons/{icon}.png", UriKind.RelativeOrAbsolute));
29+
IconImage = new Bitmap(asset);
4230
}
31+
catch { }
4332
}
4433

4534
public void Open(string repo)
@@ -52,9 +41,6 @@ public void Open(string repo)
5241
UseShellExecute = false,
5342
});
5443
}
55-
56-
private bool _isFirstTimeGetIcon = true;
57-
private Bitmap _iconImage = null;
5844
}
5945

6046
public class JetBrainsState
@@ -107,13 +93,7 @@ public void TryAdd(string name, string icon, string args, string env, Func<strin
10793
return;
10894
}
10995

110-
Founded.Add(new ExternalTool
111-
{
112-
Name = name,
113-
Icon = icon,
114-
OpenCmdArgs = args,
115-
Executable = path
116-
});
96+
Founded.Add(new ExternalTool(name, icon, path, args));
11797
}
11898

11999
public void VSCode(Func<string> platformFinder)
@@ -154,13 +134,11 @@ public void FindJetBrainsFromToolbox(Func<string> platformFinder)
154134
if (exclude.Contains(tool.ToolId.ToLowerInvariant()))
155135
continue;
156136

157-
Founded.Add(new ExternalTool
158-
{
159-
Name = $"{tool.DisplayName} {tool.DisplayVersion}",
160-
Icon = supported_icons.Contains(tool.ProductCode) ? $"JetBrains/{tool.ProductCode}" : $"JetBrains/JB",
161-
OpenCmdArgs = "\"{0}\"",
162-
Executable = Path.Combine(tool.InstallLocation, tool.LaunchCommand),
163-
});
137+
Founded.Add(new ExternalTool(
138+
$"{tool.DisplayName} {tool.DisplayVersion}",
139+
supported_icons.Contains(tool.ProductCode) ? $"JetBrains/{tool.ProductCode}" : "JetBrains/JB",
140+
Path.Combine(tool.InstallLocation, tool.LaunchCommand),
141+
"\"{0}\""));
164142
}
165143
}
166144
}

src/Native/OS.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ static OS()
4141
{
4242
throw new Exception("Platform unsupported!!!");
4343
}
44-
45-
ExternalTools = _backend.FindExternalTools();
4644
}
4745

4846
public static Models.Shell GetShell()
@@ -77,6 +75,11 @@ public static void SetupApp(AppBuilder builder)
7775
_backend.SetupApp(builder);
7876
}
7977

78+
public static void SetupEnternalTools()
79+
{
80+
ExternalTools = _backend.FindExternalTools();
81+
}
82+
8083
public static string FindGitExecutable()
8184
{
8285
return _backend.FindGitExecutable();

0 commit comments

Comments
 (0)