From e7c02dac7201c347ae9aa03ce2d100b29f3e2ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Mon, 16 Nov 2020 10:12:32 +0800 Subject: [PATCH] change SetImage to method instead of property to avoid unintended use --- Flow.Launcher/ViewModel/ResultViewModel.cs | 49 ++++++++++------------ 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/Flow.Launcher/ViewModel/ResultViewModel.cs b/Flow.Launcher/ViewModel/ResultViewModel.cs index 76c2a3e48..8ce35227f 100644 --- a/Flow.Launcher/ViewModel/ResultViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultViewModel.cs @@ -19,7 +19,7 @@ namespace Flow.Launcher.ViewModel if (result != null) { Result = result; - Image = new Lazy(() => SetImage); + Image = new Lazy(SetImage); } Settings = settings; @@ -41,38 +41,35 @@ namespace Flow.Launcher.ViewModel public Lazy Image { get; set; } - private ImageSource SetImage + private ImageSource SetImage() { - get + var imagePath = Result.IcoPath; + if (string.IsNullOrEmpty(imagePath) && Result.Icon != null) { - var imagePath = Result.IcoPath; - if (string.IsNullOrEmpty(imagePath) && Result.Icon != null) + try { - try - { - return Result.Icon(); - } - catch (Exception e) - { - Log.Exception($"|ResultViewModel.Image|IcoPath is empty and exception when calling Icon() for result <{Result.Title}> of plugin <{Result.PluginDirectory}>", e); - imagePath = Constant.MissingImgIcon; - } + return Result.Icon(); } - - 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 + catch (Exception e) { - Task.Run(() => - { - Image = new Lazy(() => ImageLoader.Load(imagePath)); - OnPropertyChanged(nameof(Image)); - }); - - return ImageLoader.LoadDefault(); + Log.Exception($"|ResultViewModel.Image|IcoPath is empty and exception when calling Icon() for result <{Result.Title}> of plugin <{Result.PluginDirectory}>", e); + imagePath = Constant.MissingImgIcon; } } + + 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 + { + Task.Run(() => + { + Image = new Lazy(() => ImageLoader.Load(imagePath)); + OnPropertyChanged(nameof(Image)); + }); + + return ImageLoader.LoadDefault(); + } } public Result Result { get; }