enhance: cache for external tool icons

This commit is contained in:
leo 2024-04-27 22:26:38 +08:00
parent 78ef955002
commit 71b9b3dfea

View file

@ -21,23 +21,27 @@ namespace SourceGit.Models
{ {
get get
{ {
if (string.IsNullOrWhiteSpace(Icon)) if (_isFirstTimeGetIcon)
{ {
return null; _isFirstTimeGetIcon = false;
}
if (!string.IsNullOrWhiteSpace(Icon))
{
try try
{ {
var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/ExternalToolIcons/{Icon}.png", UriKind.RelativeOrAbsolute)); var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/ExternalToolIcons/{Icon}.png", UriKind.RelativeOrAbsolute));
return new Bitmap(icon); _iconImage = new Bitmap(icon);
} }
catch (Exception) catch
{ {
return null;
} }
} }
} }
return _iconImage;
}
}
public void Open(string repo) public void Open(string repo)
{ {
Process.Start(new ProcessStartInfo() Process.Start(new ProcessStartInfo()
@ -48,6 +52,9 @@ namespace SourceGit.Models
UseShellExecute = false, UseShellExecute = false,
}); });
} }
private bool _isFirstTimeGetIcon = true;
private Bitmap _iconImage = null;
} }
public class JetBrainsState public class JetBrainsState