Skip to content

Commit 99086e2

Browse files
committed
change SetImage to method instead of property to avoid unintended use
1 parent 1439ee7 commit 99086e2

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

Flow.Launcher/ViewModel/ResultViewModel.cs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public ResultViewModel(Result result, Settings settings)
1919
if (result != null)
2020
{
2121
Result = result;
22-
Image = new Lazy<ImageSource>(() => SetImage);
22+
Image = new Lazy<ImageSource>(SetImage);
2323
}
2424

2525
Settings = settings;
@@ -41,37 +41,34 @@ public ResultViewModel(Result result, Settings settings)
4141

4242
public Lazy<ImageSource> Image { get; set; }
4343

44-
private ImageSource SetImage
44+
private ImageSource SetImage()
4545
{
46-
get
46+
var imagePath = Result.IcoPath;
47+
if (string.IsNullOrEmpty(imagePath) && Result.Icon != null)
4748
{
48-
var imagePath = Result.IcoPath;
49-
if (string.IsNullOrEmpty(imagePath) && Result.Icon != null)
49+
try
5050
{
51-
try
52-
{
53-
return Result.Icon();
54-
}
55-
catch (Exception e)
56-
{
57-
Log.Exception($"|ResultViewModel.Image|IcoPath is empty and exception when calling Icon() for result <{Result.Title}> of plugin <{Result.PluginDirectory}>", e);
58-
imagePath = Constant.MissingImgIcon;
59-
}
51+
return Result.Icon();
6052
}
53+
catch (Exception e)
54+
{
55+
Log.Exception($"|ResultViewModel.Image|IcoPath is empty and exception when calling Icon() for result <{Result.Title}> of plugin <{Result.PluginDirectory}>", e);
56+
imagePath = Constant.MissingImgIcon;
57+
}
58+
}
6159

62-
if (ImageLoader.CacheContainImage(imagePath))
63-
// will get here either when icoPath has value\icon delegate is null\when had exception in delegate
64-
return ImageLoader.Load(imagePath);
65-
else
60+
if (ImageLoader.CacheContainImage(imagePath))
61+
// will get here either when icoPath has value\icon delegate is null\when had exception in delegate
62+
return ImageLoader.Load(imagePath);
63+
else
64+
{
65+
Task.Run(() =>
6666
{
67-
Task.Run(() =>
68-
{
69-
Image = new Lazy<ImageSource>(() => ImageLoader.Load(imagePath));
70-
OnPropertyChanged(nameof(Image));
71-
});
67+
Image = new Lazy<ImageSource>(() => ImageLoader.Load(imagePath));
68+
OnPropertyChanged(nameof(Image));
69+
});
7270

73-
return ImageLoader.LoadDefault();
74-
}
71+
return ImageLoader.LoadDefault();
7572
}
7673
}
7774

0 commit comments

Comments
 (0)