@@ -156,7 +156,7 @@ public async Task RunSearchAsync()
156156 }
157157
158158 // Call event
159- ResultCompleted ? . Invoke ( null , new SearchResultEventArgs ( value )
159+ ResultCompleted ? . Invoke ( null , new ResultCompletedEventArgs ( value )
160160 {
161161 IsFiltered = isFiltered ,
162162 IsPriority = isPriority ,
@@ -172,35 +172,30 @@ public async Task RunSearchAsync()
172172
173173 Trace . WriteLine ( $ "{ nameof ( SearchClient ) } : { d . TotalSeconds } ") ;
174174
175- SearchCompleted ? . Invoke ( null , Results ) ;
176-
177- if ( Config . Notification ) {
178-
179-
180- var args = new ExtraResultEventArgs ( )
175+ var args2 = new SearchCompletedEventArgs ( )
176+ {
177+ Results = Results ,
178+ Best = new Lazy < ImageResult > ( FindBestResult ) ,
179+ Direct = new Lazy < ImageResult > ( ( ) =>
181180 {
182- Results = this . Results ,
183- Best = FindBestResult ( ) ,
184- } ;
185-
186- if ( Config . NotificationImage ) {
181+ if ( Config . Notification && Config . NotificationImage ) {
187182
188- Debug . WriteLine ( $ "Finding direct result") ;
183+ Debug . WriteLine ( $ "Finding direct result") ;
184+ var direct = FindDirectResult ( ) ;
189185
190- var direct = FindDirectResult ( ) ;
191-
192- if ( direct ? . Direct != null ) {
193- Debug . WriteLine ( direct ) ;
194- Debug . WriteLine ( direct . Direct . ToString ( ) ) ;
195- args . Direct = direct ;
186+ if ( direct ? . Direct != null ) {
187+ Debug . WriteLine ( direct ) ;
188+ Debug . WriteLine ( direct . Direct . ToString ( ) ) ;
189+ }
196190
191+ return direct ;
197192 }
198- }
199-
200- ExtraResults ? . Invoke ( null , args ) ;
201193
202- }
194+ return null ;
195+ } )
196+ } ;
203197
198+ SearchCompleted ? . Invoke ( null , args2 ) ;
204199 }
205200
206201 #endregion
@@ -337,36 +332,33 @@ public static BaseSearchEngine[] GetAllSearchEngines()
337332 /// <summary>
338333 /// An event that fires whenever a result is returned (<see cref="RunSearchAsync"/>).
339334 /// </summary>
340- public event EventHandler < SearchResultEventArgs > ResultCompleted ;
335+ public event EventHandler < ResultCompletedEventArgs > ResultCompleted ;
341336
342337 /// <summary>
343338 /// An event that fires when a search is complete (<see cref="RunSearchAsync"/>).
344339 /// </summary>
345- public event EventHandler < List < SearchResult > > SearchCompleted ;
346-
347- /// <summary>
348- /// An event that fires when a search is complete, with extra information
349- /// (<see cref="SearchConfig.Notification"/>; <see cref="SearchConfig.NotificationImage"/>)
350- /// </summary>
351- public event EventHandler < ExtraResultEventArgs > ExtraResults ;
340+ public event EventHandler < SearchCompletedEventArgs > SearchCompleted ;
352341
353342
354343 private const string ERR_SEARCH_NOT_COMPLETE = "Search must be completed" ;
355344
356345 private const string ERR_NO_BEST_RESULT = "Could not find best result" ;
357346 }
358347
359- public sealed class ExtraResultEventArgs : EventArgs
348+
349+ public sealed class SearchCompletedEventArgs : EventArgs
360350 {
361351 public List < SearchResult > Results { get ; init ; }
362352
363353 [ CanBeNull ]
364- public ImageResult Direct { get ; internal set ; }
354+ public Lazy < ImageResult > Direct { get ; internal set ; }
355+
365356
366- public ImageResult Best { get ; internal set ; }
357+ [ CanBeNull ]
358+ public Lazy < ImageResult > Best { get ; internal set ; }
367359 }
368360
369- public sealed class SearchResultEventArgs : EventArgs
361+ public sealed class ResultCompletedEventArgs : EventArgs
370362 {
371363 /// <summary>
372364 /// Search result
@@ -389,7 +381,7 @@ public sealed class SearchResultEventArgs : EventArgs
389381 public bool IsPriority { get ; init ; }
390382
391383
392- public SearchResultEventArgs ( SearchResult result )
384+ public ResultCompletedEventArgs ( SearchResult result )
393385 {
394386 Result = result ;
395387 }
0 commit comments