mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
add status check when base.Value has faulted
This commit is contained in:
parent
dd8a31ccd8
commit
efcb6a7833
3 changed files with 11 additions and 16 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue