Skip to content

Commit efcb6a7

Browse files
committed
add status check when base.Value has faulted
1 parent dd8a31c commit efcb6a7

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

Flow.Launcher.Infrastructure/Image/ImageCache.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ public ImageSource this[string path]
6666
{
6767
// To delete the images from the data dictionary based on the resizing of the Usage Dictionary.
6868

69-
7069
foreach (var key in Data.Where(x => x.Key != Constant.MissingImgIcon)
71-
.OrderBy(x => x.Value.usage).Take(Data.Count - MaxCached).Select(x => x.Key))
70+
.OrderBy(x => x.Value.usage)
71+
.Take(Data.Count - MaxCached)
72+
.Select(x => x.Key))
7273
{
7374
if (!(key.Equals(Constant.ErrorIcon) || key.Equals(Constant.DefaultIcon)))
7475
{
@@ -98,5 +99,4 @@ public int UniqueImagesInCache()
9899
return Data.Values.Select(x => x.imageSource).Distinct().Count();
99100
}
100101
}
101-
102102
}

Flow.Launcher.Infrastructure/Image/ImageLoader.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public static void Initialize()
3939

4040
var usage = LoadStorageToConcurrentDictionary();
4141

42-
4342
foreach (var icon in new[] { Constant.DefaultIcon, Constant.MissingImgIcon })
4443
{
4544
ImageSource img = new BitmapImage(new Uri(icon));
@@ -219,7 +218,6 @@ public static bool CacheContainImage(string path)
219218
return ImageCache.ContainsKey(path) && ImageCache[path] != null;
220219
}
221220

222-
223221
public static ImageSource Load(string path, bool loadFullImage = false)
224222
{
225223
var imageResult = LoadInternal(path, loadFullImage);

Flow.Launcher/ViewModel/ResultViewModel.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
using System.Threading.Tasks;
33
using System.Windows;
44
using System.Windows.Media;
5-
using System.Windows.Threading;
65
using Flow.Launcher.Infrastructure;
76
using Flow.Launcher.Infrastructure.Image;
87
using Flow.Launcher.Infrastructure.Logger;
98
using Flow.Launcher.Infrastructure.UserSettings;
109
using Flow.Launcher.Plugin;
11-
using Microsoft.FSharp.Core;
1210

1311
namespace Flow.Launcher.ViewModel
1412
{
@@ -18,7 +16,6 @@ public class LazyAsync<T> : Lazy<Task<T>>
1816
{
1917
private T defaultValue;
2018

21-
2219
private readonly Action _updateCallback;
2320
public new T Value
2421
{
@@ -30,13 +27,14 @@ public class LazyAsync<T> : Lazy<Task<T>>
3027
{
3128
_updateCallback();
3229
});
30+
3331
return defaultValue;
3432
}
35-
else if (!base.Value.IsCompleted)
36-
{
33+
34+
if (!base.Value.IsCompleted || base.Value.IsFaulted)
3735
return defaultValue;
38-
}
39-
else return base.Value.Result;
36+
37+
return base.Value.Result;
4038
}
4139
}
4240
public LazyAsync(Func<Task<T>> factory, T defaultValue, Action updateCallback) : base(factory)
@@ -45,8 +43,8 @@ public LazyAsync(Func<Task<T>> factory, T defaultValue, Action updateCallback) :
4543
{
4644
this.defaultValue = defaultValue;
4745
}
46+
4847
_updateCallback = updateCallback;
49-
5048
}
5149
}
5250

@@ -97,13 +95,14 @@ private async Task<ImageSource> SetImage()
9795
}
9896

9997
if (ImageLoader.CacheContainImage(imagePath))
98+
{
10099
// will get here either when icoPath has value\icon delegate is null\when had exception in delegate
101100
return ImageLoader.Load(imagePath);
101+
}
102102
else
103103
{
104104
return await Task.Run(() => ImageLoader.Load(imagePath));
105105
}
106-
107106
}
108107

109108
public Result Result { get; }
@@ -121,7 +120,6 @@ public override bool Equals(object obj)
121120
}
122121
}
123122

124-
125123
public override int GetHashCode()
126124
{
127125
return Result.GetHashCode();
@@ -131,6 +129,5 @@ public override string ToString()
131129
{
132130
return Result.ToString();
133131
}
134-
135132
}
136133
}

0 commit comments

Comments
 (0)