@@ -24,9 +24,6 @@ public static class PluginManager
24
24
{
25
25
private static readonly string ClassName = nameof ( PluginManager ) ;
26
26
27
- private static IEnumerable < PluginPair > _contextMenuPlugins ;
28
- private static IEnumerable < PluginPair > _homePlugins ;
29
-
30
27
public static List < PluginPair > AllPlugins { get ; private set ; }
31
28
public static readonly HashSet < PluginPair > GlobalPlugins = new ( ) ;
32
29
public static readonly Dictionary < string , PluginPair > NonGlobalPlugins = new ( ) ;
@@ -36,8 +33,12 @@ public static class PluginManager
36
33
private static IPublicAPI API => api ??= Ioc . Default . GetRequiredService < IPublicAPI > ( ) ;
37
34
38
35
private static PluginsSettings Settings ;
39
- private static List < PluginMetadata > _metadatas ;
40
- private static readonly List < string > _modifiedPlugins = new ( ) ;
36
+ private static readonly ConcurrentBag < string > ModifiedPlugins = new ( ) ;
37
+
38
+ private static IEnumerable < PluginPair > _contextMenuPlugins ;
39
+ private static IEnumerable < PluginPair > _homePlugins ;
40
+ private static IEnumerable < PluginPair > _resultUpdatePlugin ;
41
+ private static IEnumerable < PluginPair > _translationPlugins ;
41
42
42
43
/// <summary>
43
44
/// Directories that will hold Flow Launcher plugin directory
@@ -173,12 +174,18 @@ static PluginManager()
173
174
/// <param name="settings"></param>
174
175
public static void LoadPlugins ( PluginsSettings settings )
175
176
{
176
- _metadatas = PluginConfig . Parse ( Directories ) ;
177
+ var metadatas = PluginConfig . Parse ( Directories ) ;
177
178
Settings = settings ;
178
- Settings . UpdatePluginSettings ( _metadatas ) ;
179
- AllPlugins = PluginsLoader . Plugins ( _metadatas , Settings ) ;
179
+ Settings . UpdatePluginSettings ( metadatas ) ;
180
+ AllPlugins = PluginsLoader . Plugins ( metadatas , Settings ) ;
180
181
// Since dotnet plugins need to get assembly name first, we should update plugin directory after loading plugins
181
- UpdatePluginDirectory ( _metadatas ) ;
182
+ UpdatePluginDirectory ( metadatas ) ;
183
+
184
+ // Initialize plugin enumerable after all plugins are initialized
185
+ _contextMenuPlugins = GetPluginsForInterface < IContextMenu > ( ) ;
186
+ _homePlugins = GetPluginsForInterface < IAsyncHomeQuery > ( ) ;
187
+ _resultUpdatePlugin = GetPluginsForInterface < IResultUpdated > ( ) ;
188
+ _translationPlugins = GetPluginsForInterface < IPluginI18n > ( ) ;
182
189
}
183
190
184
191
private static void UpdatePluginDirectory ( List < PluginMetadata > metadatas )
@@ -248,9 +255,6 @@ public static async Task InitializePluginsAsync()
248
255
249
256
await Task . WhenAll ( InitTasks ) ;
250
257
251
- _contextMenuPlugins = GetPluginsForInterface < IContextMenu > ( ) ;
252
- _homePlugins = GetPluginsForInterface < IAsyncHomeQuery > ( ) ;
253
-
254
258
foreach ( var plugin in AllPlugins )
255
259
{
256
260
// set distinct on each plugin's action keywords helps only firing global(*) and action keywords once where a plugin
@@ -409,16 +413,26 @@ public static PluginPair GetPluginForId(string id)
409
413
return AllPlugins . FirstOrDefault ( o => o . Metadata . ID == id ) ;
410
414
}
411
415
412
- public static IEnumerable < PluginPair > GetPluginsForInterface < T > ( ) where T : IFeatures
416
+ private static IEnumerable < PluginPair > GetPluginsForInterface < T > ( ) where T : IFeatures
413
417
{
414
418
// Handle scenario where this is called before all plugins are instantiated, e.g. language change on startup
415
419
return AllPlugins ? . Where ( p => p . Plugin is T ) ?? Array . Empty < PluginPair > ( ) ;
416
420
}
417
421
422
+ public static IList < PluginPair > GetResultUpdatePlugin ( )
423
+ {
424
+ return _resultUpdatePlugin . Where ( p => ! PluginModified ( p . Metadata . ID ) ) . ToList ( ) ;
425
+ }
426
+
427
+ public static IList < PluginPair > GetTranslationPlugins ( )
428
+ {
429
+ return _translationPlugins . Where ( p => ! PluginModified ( p . Metadata . ID ) ) . ToList ( ) ;
430
+ }
431
+
418
432
public static List < Result > GetContextMenusForPlugin ( Result result )
419
433
{
420
434
var results = new List < Result > ( ) ;
421
- var pluginPair = _contextMenuPlugins . FirstOrDefault ( o => o . Metadata . ID == result . PluginID ) ;
435
+ var pluginPair = _contextMenuPlugins . Where ( p => ! PluginModified ( p . Metadata . ID ) ) . FirstOrDefault ( o => o . Metadata . ID == result . PluginID ) ;
422
436
if ( pluginPair != null )
423
437
{
424
438
var plugin = ( IContextMenu ) pluginPair . Plugin ;
@@ -446,7 +460,7 @@ public static List<Result> GetContextMenusForPlugin(Result result)
446
460
447
461
public static bool IsHomePlugin ( string id )
448
462
{
449
- return _homePlugins . Any ( p => p . Metadata . ID == id ) ;
463
+ return _homePlugins . Where ( p => ! PluginModified ( p . Metadata . ID ) ) . Any ( p => p . Metadata . ID == id ) ;
450
464
}
451
465
452
466
public static bool ActionKeywordRegistered ( string actionKeyword )
@@ -544,7 +558,7 @@ private static bool SameOrLesserPluginVersionExists(string metadataPath)
544
558
545
559
public static bool PluginModified ( string id )
546
560
{
547
- return _modifiedPlugins . Contains ( id ) ;
561
+ return ModifiedPlugins . Contains ( id ) ;
548
562
}
549
563
550
564
public static async Task < bool > UpdatePluginAsync ( PluginMetadata existingVersion , UserPlugin newVersion , string zipFilePath )
@@ -655,7 +669,7 @@ internal static bool InstallPlugin(UserPlugin plugin, string zipFilePath, bool c
655
669
656
670
if ( checkModified )
657
671
{
658
- _modifiedPlugins . Add ( plugin . ID ) ;
672
+ ModifiedPlugins . Add ( plugin . ID ) ;
659
673
}
660
674
661
675
return true ;
@@ -721,14 +735,20 @@ internal static async Task<bool> UninstallPluginAsync(PluginMetadata plugin, boo
721
735
}
722
736
Settings . RemovePluginSettings ( plugin . ID ) ;
723
737
AllPlugins . RemoveAll ( p => p . Metadata . ID == plugin . ID ) ;
738
+ GlobalPlugins . RemoveWhere ( p => p . Metadata . ID == plugin . ID ) ;
739
+ var keysToRemove = NonGlobalPlugins . Where ( p => p . Value . Metadata . ID == plugin . ID ) . Select ( p => p . Key ) . ToList ( ) ;
740
+ foreach ( var key in keysToRemove )
741
+ {
742
+ NonGlobalPlugins . Remove ( key ) ;
743
+ }
724
744
}
725
745
726
746
// Marked for deletion. Will be deleted on next start up
727
747
using var _ = File . CreateText ( Path . Combine ( plugin . PluginDirectory , "NeedDelete.txt" ) ) ;
728
748
729
749
if ( checkModified )
730
750
{
731
- _modifiedPlugins . Add ( plugin . ID ) ;
751
+ ModifiedPlugins . Add ( plugin . ID ) ;
732
752
}
733
753
734
754
return true ;
0 commit comments