1
- using System ;
1
+ using System ;
2
2
using System . Collections . Concurrent ;
3
3
using System . Collections . Generic ;
4
4
using System . IO ;
9
9
using CommunityToolkit . Mvvm . DependencyInjection ;
10
10
using Flow . Launcher . Core . ExternalPlugins ;
11
11
using Flow . Launcher . Infrastructure ;
12
+ using Flow . Launcher . Infrastructure . DialogJump ;
12
13
using Flow . Launcher . Infrastructure . UserSettings ;
13
14
using Flow . Launcher . Plugin ;
14
15
using Flow . Launcher . Plugin . SharedCommands ;
@@ -40,6 +41,9 @@ public static class PluginManager
40
41
private static IEnumerable < PluginPair > _resultUpdatePlugin ;
41
42
private static IEnumerable < PluginPair > _translationPlugins ;
42
43
44
+ private static readonly List < DialogJumpExplorerPair > _dialogJumpExplorerPlugins = new ( ) ;
45
+ private static readonly List < DialogJumpDialogPair > _dialogJumpDialogPlugins = new ( ) ;
46
+
43
47
/// <summary>
44
48
/// Directories that will hold Flow Launcher plugin directory
45
49
/// </summary>
@@ -186,6 +190,24 @@ public static void LoadPlugins(PluginsSettings settings)
186
190
_homePlugins = GetPluginsForInterface < IAsyncHomeQuery > ( ) ;
187
191
_resultUpdatePlugin = GetPluginsForInterface < IResultUpdated > ( ) ;
188
192
_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
+ }
189
211
}
190
212
191
213
private static void UpdatePluginDirectory ( List < PluginMetadata > metadatas )
@@ -288,20 +310,24 @@ public static async Task InitializePluginsAsync()
288
310
}
289
311
}
290
312
291
- public static ICollection < PluginPair > ValidPluginsForQuery ( Query query )
313
+ public static ICollection < PluginPair > ValidPluginsForQuery ( Query query , bool dialogJump )
292
314
{
293
315
if ( query is null )
294
316
return Array . Empty < PluginPair > ( ) ;
295
317
296
318
if ( ! NonGlobalPlugins . TryGetValue ( query . ActionKeyword , out var plugin ) )
297
319
{
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 ( ) ;
299
324
}
300
325
326
+ if ( dialogJump && plugin . Plugin is not IAsyncDialogJump )
327
+ return Array . Empty < PluginPair > ( ) ;
328
+
301
329
if ( API . PluginModified ( plugin . Metadata . ID ) )
302
- {
303
330
return Array . Empty < PluginPair > ( ) ;
304
- }
305
331
306
332
return new List < PluginPair >
307
333
{
@@ -388,6 +414,36 @@ public static async Task<List<Result>> QueryHomeForPluginAsync(PluginPair pair,
388
414
return results ;
389
415
}
390
416
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
+
391
447
public static void UpdatePluginMetadata ( IReadOnlyList < Result > results , PluginMetadata metadata , Query query )
392
448
{
393
449
foreach ( var r in results )
@@ -463,6 +519,16 @@ public static bool IsHomePlugin(string id)
463
519
return _homePlugins . Where ( p => ! PluginModified ( p . Metadata . ID ) ) . Any ( p => p . Metadata . ID == id ) ;
464
520
}
465
521
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
+
466
532
public static bool ActionKeywordRegistered ( string actionKeyword )
467
533
{
468
534
// 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
719
785
catch ( Exception e )
720
786
{
721
787
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" ) ,
723
789
string . Format ( API . GetTranslation ( "failedToRemovePluginSettingsMessage" ) , plugin . Name ) ) ;
724
790
}
725
791
}
@@ -735,7 +801,7 @@ internal static async Task<bool> UninstallPluginAsync(PluginMetadata plugin, boo
735
801
catch ( Exception e )
736
802
{
737
803
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" ) ,
739
805
string . Format ( API . GetTranslation ( "failedToRemovePluginCacheMessage" ) , plugin . Name ) ) ;
740
806
}
741
807
Settings . RemovePluginSettings ( plugin . ID ) ;
0 commit comments