1212
1313namespace Flow . Launcher . Plugin . PluginsManager
1414{
15- public class Main : ISettingProvider , IAsyncPlugin , IContextMenu , IPluginI18n , IAsyncReloadable
15+ public class Main : ISettingProvider , IAsyncPlugin , IContextMenu , IPluginI18n
1616 {
1717 internal PluginInitContext Context { get ; set ; }
1818
@@ -24,64 +24,41 @@ public class Main : ISettingProvider, IAsyncPlugin, IContextMenu, IPluginI18n, I
2424
2525 internal PluginsManager pluginManager ;
2626
27- private DateTime lastUpdateTime = DateTime . MinValue ;
28-
2927 public Control CreateSettingPanel ( )
3028 {
3129 return new PluginsManagerSettings ( viewModel ) ;
3230 }
3331
34- public Task InitAsync ( PluginInitContext context )
32+ public async Task InitAsync ( PluginInitContext context )
3533 {
3634 Context = context ;
3735 Settings = context . API . LoadSettingJsonStorage < Settings > ( ) ;
3836 viewModel = new SettingsViewModel ( context , Settings ) ;
3937 contextMenu = new ContextMenu ( Context ) ;
4038 pluginManager = new PluginsManager ( Context , Settings ) ;
41- _manifestUpdateTask = pluginManager
42- . UpdateManifestAsync ( true )
43- . ContinueWith ( _ =>
44- {
45- lastUpdateTime = DateTime . Now ;
46- } , TaskContinuationOptions . OnlyOnRanToCompletion ) ;
4739
48- return Task . CompletedTask ;
40+ await pluginManager . UpdateManifestAsync ( ) ;
4941 }
5042
5143 public List < Result > LoadContextMenus ( Result selectedResult )
5244 {
5345 return contextMenu . LoadContextMenus ( selectedResult ) ;
5446 }
5547
56- private Task _manifestUpdateTask = Task . CompletedTask ;
57-
5848 public async Task < List < Result > > QueryAsync ( Query query , CancellationToken token )
5949 {
60- var search = query . Search ;
61-
62- if ( string . IsNullOrWhiteSpace ( search ) )
50+ if ( string . IsNullOrWhiteSpace ( query . Search ) )
6351 return pluginManager . GetDefaultHotKeys ( ) ;
6452
65- if ( ( DateTime . Now - lastUpdateTime ) . TotalHours > 12 && _manifestUpdateTask . IsCompleted ) // 12 hours
66- {
67- _manifestUpdateTask = pluginManager . UpdateManifestAsync ( ) . ContinueWith ( t =>
68- {
69- lastUpdateTime = DateTime . Now ;
70- } , TaskContinuationOptions . OnlyOnRanToCompletion ) ;
71- }
72-
73- return search switch
53+ return query . FirstSearch . ToLower ( ) switch
7454 {
7555 //search could be url, no need ToLower() when passed in
76- var s when s . StartsWith ( Settings . HotKeyInstall , StringComparison . OrdinalIgnoreCase )
77- => await pluginManager . RequestInstallOrUpdate ( search , token ) ,
78- var s when s . StartsWith ( Settings . HotkeyUninstall , StringComparison . OrdinalIgnoreCase )
79- => pluginManager . RequestUninstall ( search ) ,
80- var s when s . StartsWith ( Settings . HotkeyUpdate , StringComparison . OrdinalIgnoreCase )
81- => await pluginManager . RequestUpdate ( search , token ) ,
56+ Settings . InstallCommand => await pluginManager . RequestInstallOrUpdate ( query . SecondToEndSearch , token ) ,
57+ Settings . UninstallCommand => pluginManager . RequestUninstall ( query . SecondToEndSearch ) ,
58+ Settings . UpdateCommand => await pluginManager . RequestUpdate ( query . SecondToEndSearch , token ) ,
8259 _ => pluginManager . GetDefaultHotKeys ( ) . Where ( hotkey =>
8360 {
84- hotkey . Score = StringMatcher . FuzzySearch ( search , hotkey . Title ) . Score ;
61+ hotkey . Score = StringMatcher . FuzzySearch ( query . Search , hotkey . Title ) . Score ;
8562 return hotkey . Score > 0 ;
8663 } ) . ToList ( )
8764 } ;
@@ -96,11 +73,5 @@ public string GetTranslatedPluginDescription()
9673 {
9774 return Context . API . GetTranslation ( "plugin_pluginsmanager_plugin_description" ) ;
9875 }
99-
100- public async Task ReloadDataAsync ( )
101- {
102- await pluginManager . UpdateManifestAsync ( ) ;
103- lastUpdateTime = DateTime . Now ;
104- }
10576 }
10677}
0 commit comments