12
12
13
13
namespace Flow . Launcher . Plugin . PluginsManager
14
14
{
15
- public class Main : ISettingProvider , IAsyncPlugin , IContextMenu , IPluginI18n , IAsyncReloadable
15
+ public class Main : ISettingProvider , IAsyncPlugin , IContextMenu , IPluginI18n
16
16
{
17
17
internal PluginInitContext Context { get ; set ; }
18
18
@@ -24,64 +24,41 @@ public class Main : ISettingProvider, IAsyncPlugin, IContextMenu, IPluginI18n, I
24
24
25
25
internal PluginsManager pluginManager ;
26
26
27
- private DateTime lastUpdateTime = DateTime . MinValue ;
28
-
29
27
public Control CreateSettingPanel ( )
30
28
{
31
29
return new PluginsManagerSettings ( viewModel ) ;
32
30
}
33
31
34
- public Task InitAsync ( PluginInitContext context )
32
+ public async Task InitAsync ( PluginInitContext context )
35
33
{
36
34
Context = context ;
37
35
Settings = context . API . LoadSettingJsonStorage < Settings > ( ) ;
38
36
viewModel = new SettingsViewModel ( context , Settings ) ;
39
37
contextMenu = new ContextMenu ( Context ) ;
40
38
pluginManager = new PluginsManager ( Context , Settings ) ;
41
- _manifestUpdateTask = pluginManager
42
- . UpdateManifestAsync ( true )
43
- . ContinueWith ( _ =>
44
- {
45
- lastUpdateTime = DateTime . Now ;
46
- } , TaskContinuationOptions . OnlyOnRanToCompletion ) ;
47
39
48
- return Task . CompletedTask ;
40
+ await pluginManager . UpdateManifestAsync ( ) ;
49
41
}
50
42
51
43
public List < Result > LoadContextMenus ( Result selectedResult )
52
44
{
53
45
return contextMenu . LoadContextMenus ( selectedResult ) ;
54
46
}
55
47
56
- private Task _manifestUpdateTask = Task . CompletedTask ;
57
-
58
48
public async Task < List < Result > > QueryAsync ( Query query , CancellationToken token )
59
49
{
60
- var search = query . Search ;
61
-
62
- if ( string . IsNullOrWhiteSpace ( search ) )
50
+ if ( string . IsNullOrWhiteSpace ( query . Search ) )
63
51
return pluginManager . GetDefaultHotKeys ( ) ;
64
52
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
74
54
{
75
55
//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 ) ,
82
59
_ => pluginManager . GetDefaultHotKeys ( ) . Where ( hotkey =>
83
60
{
84
- hotkey . Score = StringMatcher . FuzzySearch ( search , hotkey . Title ) . Score ;
61
+ hotkey . Score = StringMatcher . FuzzySearch ( query . Search , hotkey . Title ) . Score ;
85
62
return hotkey . Score > 0 ;
86
63
} ) . ToList ( )
87
64
} ;
@@ -96,11 +73,5 @@ public string GetTranslatedPluginDescription()
96
73
{
97
74
return Context . API . GetTranslation ( "plugin_pluginsmanager_plugin_description" ) ;
98
75
}
99
-
100
- public async Task ReloadDataAsync ( )
101
- {
102
- await pluginManager . UpdateManifestAsync ( ) ;
103
- lastUpdateTime = DateTime . Now ;
104
- }
105
76
}
106
77
}
0 commit comments