@@ -173,50 +173,53 @@ public ImageSource PreviewImage
173
173
174
174
public GlyphInfo Glyph { get ; set ; }
175
175
176
- private async Task LoadImageAsync ( )
176
+ private async Task < ImageSource > LoadImageInternalAsync ( string imagePath , Result . IconDelegate icon , bool loadFullImage )
177
177
{
178
- var imagePath = Result . IcoPath ;
179
- if ( string . IsNullOrEmpty ( imagePath ) && Result . Icon != null )
178
+ if ( string . IsNullOrEmpty ( imagePath ) && icon != null )
180
179
{
181
180
try
182
181
{
183
- image = Result . Icon ( ) ;
184
- return ;
182
+ var image = await Task . Run ( ( ) => icon ( ) ) . ConfigureAwait ( false ) ;
183
+ return image ;
185
184
}
186
185
catch ( Exception e )
187
186
{
188
187
Log . Exception (
189
- $ "|ResultViewModel.Image |IcoPath is empty and exception when calling Icon() for result <{ Result . Title } > of plugin <{ Result . PluginDirectory } >",
188
+ $ "|ResultViewModel.LoadImageInternalAsync |IcoPath is empty and exception when calling IconDelegate for result <{ Result . Title } > of plugin <{ Result . PluginDirectory } >",
190
189
e ) ;
191
190
}
192
191
}
193
192
194
- var loadFullImage = ( Path . GetExtension ( imagePath ) ?? "" ) . Equals ( ".url" , StringComparison . OrdinalIgnoreCase ) ;
193
+ return await ImageLoader . LoadAsync ( imagePath , loadFullImage ) . ConfigureAwait ( false ) ;
194
+ }
195
195
196
- if ( ImageLoader . CacheContainImage ( imagePath ) )
196
+ private async Task LoadImageAsync ( )
197
+ {
198
+ var imagePath = Result . IcoPath ;
199
+ var iconDelegate = Result . Icon ;
200
+ if ( ImageLoader . CacheContainImage ( imagePath , false ) )
197
201
{
198
- // will get here either when icoPath has value\icon delegate is null\when had exception in delegate
199
- image = await ImageLoader . LoadAsync ( imagePath , loadFullImage ) . ConfigureAwait ( false ) ;
200
- return ;
202
+ image = await LoadImageInternalAsync ( imagePath , iconDelegate , false ) . ConfigureAwait ( false ) ;
203
+ }
204
+ else
205
+ {
206
+ // We need to modify the property not field here to trigger the OnPropertyChanged event
207
+ Image = await LoadImageInternalAsync ( imagePath , iconDelegate , false ) . ConfigureAwait ( false ) ;
201
208
}
202
-
203
- // We need to modify the property not field here to trigger the OnPropertyChanged event
204
- Image = await ImageLoader . LoadAsync ( imagePath , loadFullImage ) . ConfigureAwait ( false ) ;
205
209
}
206
210
207
-
208
211
private async Task LoadPreviewImageAsync ( )
209
212
{
210
213
var imagePath = Result . PreviewImage ?? Result . IcoPath ;
211
- if ( imagePath == null && Result . Icon != null )
214
+ var iconDelegate = Result . Icon ;
215
+ if ( ImageLoader . CacheContainImage ( imagePath , true ) )
212
216
{
213
- // For UWP programs from program plugin
214
- // TODO: Consider https://github.com/Flow-Launcher/Flow.Launcher/pull/1492#issuecomment-1304829947
215
- PreviewImage = Result . Icon ( ) ;
217
+ previewImage = await LoadImageInternalAsync ( imagePath , iconDelegate , true ) . ConfigureAwait ( false ) ;
216
218
}
217
219
else
218
220
{
219
- PreviewImage = await ImageLoader . LoadAsync ( imagePath , true ) . ConfigureAwait ( false ) ;
221
+ // We need to modify the property not field here to trigger the OnPropertyChanged event
222
+ PreviewImage = await LoadImageInternalAsync ( imagePath , iconDelegate , true ) . ConfigureAwait ( false ) ;
220
223
}
221
224
}
222
225
0 commit comments