1- using System ;
1+ using System ;
22using System . Collections . Concurrent ;
33using System . Collections . Generic ;
44using System . IO ;
99using CommunityToolkit . Mvvm . DependencyInjection ;
1010using Flow . Launcher . Core . ExternalPlugins ;
1111using Flow . Launcher . Infrastructure ;
12+ using Flow . Launcher . Infrastructure . DialogJump ;
1213using Flow . Launcher . Infrastructure . UserSettings ;
1314using Flow . Launcher . Plugin ;
1415using Flow . Launcher . Plugin . SharedCommands ;
@@ -40,6 +41,9 @@ public static class PluginManager
4041 private static IEnumerable < PluginPair > _resultUpdatePlugin ;
4142 private static IEnumerable < PluginPair > _translationPlugins ;
4243
44+ private static readonly List < DialogJumpExplorerPair > _dialogJumpExplorerPlugins = new ( ) ;
45+ private static readonly List < DialogJumpDialogPair > _dialogJumpDialogPlugins = new ( ) ;
46+
4347 /// <summary>
4448 /// Directories that will hold Flow Launcher plugin directory
4549 /// </summary>
@@ -186,6 +190,24 @@ public static void LoadPlugins(PluginsSettings settings)
186190 _homePlugins = GetPluginsForInterface < IAsyncHomeQuery > ( ) ;
187191 _resultUpdatePlugin = GetPluginsForInterface < IResultUpdated > ( ) ;
188192 _translationPlugins = GetPluginsForInterface < IPluginI18n > ( ) ;
193+
194+ // Initialize Dialog Jump plugin pairs
195+ foreach ( var pair in GetPluginsForInterface < IDialogJumpExplorer > ( ) )
196+ {
197+ _dialogJumpExplorerPlugins . Add ( new DialogJumpExplorerPair
198+ {
199+ Plugin = ( IDialogJumpExplorer ) pair . Plugin ,
200+ Metadata = pair . Metadata
201+ } ) ;
202+ }
203+ foreach ( var pair in GetPluginsForInterface < IDialogJumpDialog > ( ) )
204+ {
205+ _dialogJumpDialogPlugins . Add ( new DialogJumpDialogPair
206+ {
207+ Plugin = ( IDialogJumpDialog ) pair . Plugin ,
208+ Metadata = pair . Metadata
209+ } ) ;
210+ }
189211 }
190212
191213 private static void UpdatePluginDirectory ( List < PluginMetadata > metadatas )
@@ -288,20 +310,24 @@ public static async Task InitializePluginsAsync()
288310 }
289311 }
290312
291- public static ICollection < PluginPair > ValidPluginsForQuery ( Query query )
313+ public static ICollection < PluginPair > ValidPluginsForQuery ( Query query , bool dialogJump )
292314 {
293315 if ( query is null )
294316 return Array . Empty < PluginPair > ( ) ;
295317
296318 if ( ! NonGlobalPlugins . TryGetValue ( query . ActionKeyword , out var plugin ) )
297319 {
298- return GlobalPlugins . Where ( p => ! PluginModified ( p . Metadata . ID ) ) . ToList ( ) ;
320+ if ( dialogJump )
321+ return GlobalPlugins . Where ( p => p . Plugin is IAsyncDialogJump && ! PluginModified ( p . Metadata . ID ) ) . ToList ( ) ;
322+ else
323+ return GlobalPlugins . Where ( p => ! PluginModified ( p . Metadata . ID ) ) . ToList ( ) ;
299324 }
300325
326+ if ( dialogJump && plugin . Plugin is not IAsyncDialogJump )
327+ return Array . Empty < PluginPair > ( ) ;
328+
301329 if ( API . PluginModified ( plugin . Metadata . ID ) )
302- {
303330 return Array . Empty < PluginPair > ( ) ;
304- }
305331
306332 return new List < PluginPair >
307333 {
@@ -388,6 +414,36 @@ public static async Task<List<Result>> QueryHomeForPluginAsync(PluginPair pair,
388414 return results ;
389415 }
390416
417+ public static async Task < List < DialogJumpResult > > QueryDialogJumpForPluginAsync ( PluginPair pair , Query query , CancellationToken token )
418+ {
419+ var results = new List < DialogJumpResult > ( ) ;
420+ var metadata = pair . Metadata ;
421+
422+ try
423+ {
424+ var milliseconds = await API . StopwatchLogDebugAsync ( ClassName , $ "Cost for { metadata . Name } ",
425+ async ( ) => results = await ( ( IAsyncDialogJump ) pair . Plugin ) . QueryDialogJumpAsync ( query , token ) . ConfigureAwait ( false ) ) ;
426+
427+ token . ThrowIfCancellationRequested ( ) ;
428+ if ( results == null )
429+ return null ;
430+ UpdatePluginMetadata ( results , metadata , query ) ;
431+
432+ token . ThrowIfCancellationRequested ( ) ;
433+ }
434+ catch ( OperationCanceledException )
435+ {
436+ // null will be fine since the results will only be added into queue if the token hasn't been cancelled
437+ return null ;
438+ }
439+ catch ( Exception e )
440+ {
441+ API . LogException ( ClassName , $ "Failed to query Dialog Jump for plugin: { metadata . Name } ", e ) ;
442+ return null ;
443+ }
444+ return results ;
445+ }
446+
391447 public static void UpdatePluginMetadata ( IReadOnlyList < Result > results , PluginMetadata metadata , Query query )
392448 {
393449 foreach ( var r in results )
@@ -463,6 +519,16 @@ public static bool IsHomePlugin(string id)
463519 return _homePlugins . Where ( p => ! PluginModified ( p . Metadata . ID ) ) . Any ( p => p . Metadata . ID == id ) ;
464520 }
465521
522+ public static IList < DialogJumpExplorerPair > GetDialogJumpExplorers ( )
523+ {
524+ return _dialogJumpExplorerPlugins . Where ( p => ! PluginModified ( p . Metadata . ID ) ) . ToList ( ) ;
525+ }
526+
527+ public static IList < DialogJumpDialogPair > GetDialogJumpDialogs ( )
528+ {
529+ return _dialogJumpDialogPlugins . Where ( p => ! PluginModified ( p . Metadata . ID ) ) . ToList ( ) ;
530+ }
531+
466532 public static bool ActionKeywordRegistered ( string actionKeyword )
467533 {
468534 // this method is only checking for action keywords (defined as not '*') registration
@@ -719,7 +785,7 @@ internal static async Task<bool> UninstallPluginAsync(PluginMetadata plugin, boo
719785 catch ( Exception e )
720786 {
721787 API . LogException ( ClassName , $ "Failed to delete plugin settings folder for { plugin . Name } ", e ) ;
722- API . ShowMsg ( API . GetTranslation ( "failedToRemovePluginSettingsTitle" ) ,
788+ API . ShowMsgError ( API . GetTranslation ( "failedToRemovePluginSettingsTitle" ) ,
723789 string . Format ( API . GetTranslation ( "failedToRemovePluginSettingsMessage" ) , plugin . Name ) ) ;
724790 }
725791 }
@@ -735,7 +801,7 @@ internal static async Task<bool> UninstallPluginAsync(PluginMetadata plugin, boo
735801 catch ( Exception e )
736802 {
737803 API . LogException ( ClassName , $ "Failed to delete plugin cache folder for { plugin . Name } ", e ) ;
738- API . ShowMsg ( API . GetTranslation ( "failedToRemovePluginCacheTitle" ) ,
804+ API . ShowMsgError ( API . GetTranslation ( "failedToRemovePluginCacheTitle" ) ,
739805 string . Format ( API . GetTranslation ( "failedToRemovePluginCacheMessage" ) , plugin . Name ) ) ;
740806 }
741807 Settings . RemovePluginSettings ( plugin . ID ) ;
0 commit comments