From 71b9b3dfea74b6592c6831bc1656472607ef1391 Mon Sep 17 00:00:00 2001 From: leo Date: Sat, 27 Apr 2024 22:26:38 +0800 Subject: [PATCH] enhance: cache for external tool icons --- src/Models/ExternalTool.cs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Models/ExternalTool.cs b/src/Models/ExternalTool.cs index 5f1afcaa..f1760829 100644 --- a/src/Models/ExternalTool.cs +++ b/src/Models/ExternalTool.cs @@ -21,20 +21,24 @@ namespace SourceGit.Models { 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 - { - var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/ExternalToolIcons/{Icon}.png", UriKind.RelativeOrAbsolute)); - return new Bitmap(icon); - } - catch (Exception) - { - return null; - } + return _iconImage; } } @@ -48,6 +52,9 @@ namespace SourceGit.Models UseShellExecute = false, }); } + + private bool _isFirstTimeGetIcon = true; + private Bitmap _iconImage = null; } public class JetBrainsState