add status check when base.Value has faulted

This commit is contained in:
Jeremy Wu 2020-11-26 20:47:04 +11:00
parent dd8a31ccd8
commit efcb6a7833
3 changed files with 11 additions and 16 deletions

View file

@ -66,9 +66,10 @@ namespace Flow.Launcher.Infrastructure.Image
{
// To delete the images from the data dictionary based on the resizing of the Usage Dictionary.
foreach (var key in Data.Where(x => x.Key != Constant.MissingImgIcon)
.OrderBy(x => x.Value.usage).Take(Data.Count - MaxCached).Select(x => x.Key))
.OrderBy(x => x.Value.usage)
.Take(Data.Count - MaxCached)
.Select(x => x.Key))
{
if (!(key.Equals(Constant.ErrorIcon) || key.Equals(Constant.DefaultIcon)))
{
@ -98,5 +99,4 @@ namespace Flow.Launcher.Infrastructure.Image
return Data.Values.Select(x => x.imageSource).Distinct().Count();
}
}
}

View file

@ -39,7 +39,6 @@ namespace Flow.Launcher.Infrastructure.Image
var usage = LoadStorageToConcurrentDictionary();
foreach (var icon in new[] { Constant.DefaultIcon, Constant.MissingImgIcon })
{
ImageSource img = new BitmapImage(new Uri(icon));
@ -219,7 +218,6 @@ namespace Flow.Launcher.Infrastructure.Image
return ImageCache.ContainsKey(path) && ImageCache[path] != null;
}
public static ImageSource Load(string path, bool loadFullImage = false)
{
var imageResult = LoadInternal(path, loadFullImage);

View file

@ -2,13 +2,11 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.Image;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
using Microsoft.FSharp.Core;
namespace Flow.Launcher.ViewModel
{
@ -18,7 +16,6 @@ namespace Flow.Launcher.ViewModel
{
private T defaultValue;
private readonly Action _updateCallback;
public new T Value
{
@ -30,13 +27,14 @@ namespace Flow.Launcher.ViewModel
{
_updateCallback();
});
return defaultValue;
}
else if (!base.Value.IsCompleted)
{
if (!base.Value.IsCompleted || base.Value.IsFaulted)
return defaultValue;
}
else return base.Value.Result;
return base.Value.Result;
}
}
public LazyAsync(Func<Task<T>> factory, T defaultValue, Action updateCallback) : base(factory)
@ -45,8 +43,8 @@ namespace Flow.Launcher.ViewModel
{
this.defaultValue = defaultValue;
}
_updateCallback = updateCallback;
}
}
@ -97,13 +95,14 @@ namespace Flow.Launcher.ViewModel
}
if (ImageLoader.CacheContainImage(imagePath))
{
// will get here either when icoPath has value\icon delegate is null\when had exception in delegate
return ImageLoader.Load(imagePath);
}
else
{
return await Task.Run(() => ImageLoader.Load(imagePath));
}
}
public Result Result { get; }
@ -121,7 +120,6 @@ namespace Flow.Launcher.ViewModel
}
}
public override int GetHashCode()
{
return Result.GetHashCode();
@ -131,6 +129,5 @@ namespace Flow.Launcher.ViewModel
{
return Result.ToString();
}
}
}