mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add TryGetValue for ImageLoader
This commit is contained in:
parent
35d96bde84
commit
e83e21dddb
3 changed files with 24 additions and 4 deletions
|
|
@ -87,6 +87,21 @@ namespace Flow.Launcher.Infrastructure.Image
|
|||
return key is not null && Data.ContainsKey((key, isFullImage)) && Data[(key, isFullImage)].imageSource != null;
|
||||
}
|
||||
|
||||
public bool TryGetValue(string key, bool isFullImage, out ImageSource image)
|
||||
{
|
||||
if (key is not null)
|
||||
{
|
||||
bool hasKey = Data.TryGetValue((key, isFullImage), out var imageUsage);
|
||||
image = hasKey ? imageUsage.imageSource : null;
|
||||
return hasKey;
|
||||
}
|
||||
else
|
||||
{
|
||||
image = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int CacheSize()
|
||||
{
|
||||
return Data.Count;
|
||||
|
|
|
|||
|
|
@ -251,6 +251,11 @@ namespace Flow.Launcher.Infrastructure.Image
|
|||
return ImageCache.ContainsKey(path, false) && ImageCache[path, loadFullImage] != null;
|
||||
}
|
||||
|
||||
public static bool TryGetValue(string path, bool loadFullImage, out ImageSource image)
|
||||
{
|
||||
return ImageCache.TryGetValue(path, loadFullImage, out image);
|
||||
}
|
||||
|
||||
public static async ValueTask<ImageSource> LoadAsync(string path, bool loadFullImage = false)
|
||||
{
|
||||
var imageResult = await LoadInternalAsync(path, loadFullImage);
|
||||
|
|
|
|||
|
|
@ -214,9 +214,9 @@ namespace Flow.Launcher.ViewModel
|
|||
{
|
||||
var imagePath = Result.IcoPath;
|
||||
var iconDelegate = Result.Icon;
|
||||
if (ImageLoader.CacheContainImage(imagePath, false))
|
||||
if (ImageLoader.TryGetValue(imagePath, false, out ImageSource img))
|
||||
{
|
||||
image = await LoadImageInternalAsync(imagePath, iconDelegate, false).ConfigureAwait(false);
|
||||
image = img;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -229,9 +229,9 @@ namespace Flow.Launcher.ViewModel
|
|||
{
|
||||
var imagePath = Result.Preview.PreviewImagePath ?? Result.IcoPath;
|
||||
var iconDelegate = Result.Preview.PreviewDelegate ?? Result.Icon;
|
||||
if (ImageLoader.CacheContainImage(imagePath, true))
|
||||
if (ImageLoader.TryGetValue(imagePath, true, out ImageSource img))
|
||||
{
|
||||
previewImage = await LoadImageInternalAsync(imagePath, iconDelegate, true).ConfigureAwait(false);
|
||||
previewImage = img;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue