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,20 +21,24 @@ namespace SourceGit.Models
{ {
get get
{ {
if (string.IsNullOrWhiteSpace(Icon)) if (_isFirstTimeGetIcon)
{ {
return null; _isFirstTimeGetIcon = false;
if (!string.IsNullOrWhiteSpace(Icon))
{
try
{
var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/ExternalToolIcons/{Icon}.png", UriKind.RelativeOrAbsolute));
_iconImage = new Bitmap(icon);
}
catch
{
}
}
} }
try return _iconImage;
{
var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/ExternalToolIcons/{Icon}.png", UriKind.RelativeOrAbsolute));
return new Bitmap(icon);
}
catch (Exception)
{
return null;
}
} }
} }
@ -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