@@ -14,32 +14,36 @@ namespace Flow.Launcher.Plugin.PluginsManager
14
14
internal class PluginsManager
15
15
{
16
16
private readonly PluginsManifest pluginsManifest ;
17
+
17
18
private PluginInitContext Context { get ; set ; }
18
19
20
+ private Settings Settings { get ; set ; }
21
+
19
22
private readonly string icoPath = "Images\\ pluginsmanager.png" ;
20
23
21
- internal PluginsManager ( PluginInitContext context )
24
+ internal PluginsManager ( PluginInitContext context , Settings settings )
22
25
{
23
26
pluginsManifest = new PluginsManifest ( ) ;
24
27
Context = context ;
28
+ Settings = settings ;
25
29
}
26
30
internal void InstallOrUpdate ( UserPlugin plugin )
27
31
{
28
- if ( PluginExists ( plugin . ID ) )
32
+ if ( PluginExists ( plugin . ID ) )
29
33
{
30
34
Context . API . ShowMsg ( "Plugin already installed" ) ;
31
35
return ;
32
36
}
33
37
34
- var message = string . Format ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_prompt" ) ,
35
- Environment . NewLine , Environment . NewLine ,
38
+ var message = string . Format ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_prompt" ) ,
39
+ Environment . NewLine , Environment . NewLine ,
36
40
plugin . Name , plugin . Author ) ;
37
41
38
- if ( MessageBox . Show ( message , Context . API . GetTranslation ( "plugin_pluginsmanager_install_title" ) , MessageBoxButton . YesNo ) == MessageBoxResult . No )
42
+ if ( MessageBox . Show ( message , Context . API . GetTranslation ( "plugin_pluginsmanager_install_title" ) , MessageBoxButton . YesNo ) == MessageBoxResult . No )
39
43
return ;
40
44
41
45
var filePath = Path . Combine ( DataLocation . PluginsDirectory , $ "{ plugin . Name } { plugin . ID } .zip") ;
42
-
46
+
43
47
try
44
48
{
45
49
Context . API . ShowMsg ( Context . API . GetTranslation ( "plugin_pluginsmanager_downloading_plugin" ) ,
@@ -89,14 +93,14 @@ internal List<Result> Search(List<Result> results, string searchName)
89
93
if ( matchResult . IsSearchPrecisionScoreMet ( ) )
90
94
x . Score = matchResult . Score ;
91
95
92
- return matchResult . IsSearchPrecisionScoreMet ( ) ;
96
+ return matchResult . IsSearchPrecisionScoreMet ( ) ;
93
97
} )
94
98
. ToList ( ) ;
95
99
}
96
100
97
101
internal List < Result > RequestInstallOrUpdate ( string searchName )
98
102
{
99
- var results =
103
+ var results =
100
104
pluginsManifest
101
105
. UserPlugins
102
106
. Select ( x =>
@@ -122,10 +126,10 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
122
126
{
123
127
if ( ! File . Exists ( downloadedFilePath ) )
124
128
return ;
125
-
129
+
126
130
var tempFolderPath = Path . Combine ( Path . GetTempPath ( ) , "flowlauncher" ) ;
127
131
var tempFolderPluginPath = Path . Combine ( tempFolderPath , "plugin" ) ;
128
-
132
+
129
133
if ( Directory . Exists ( tempFolderPath ) )
130
134
Directory . Delete ( tempFolderPath , true ) ;
131
135
@@ -150,18 +154,44 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
150
154
}
151
155
152
156
string newPluginPath = Path . Combine ( DataLocation . PluginsDirectory , $ "{ plugin . Name } { plugin . ID } ") ;
153
-
157
+
154
158
Directory . Move ( pluginFolderPath , newPluginPath ) ;
155
159
156
- if ( MessageBox . Show ( string . Format ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_successandrestart" ) ,
160
+ if ( MessageBox . Show ( string . Format ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_successandrestart" ) ,
157
161
plugin . Name , Environment . NewLine ) ,
158
- Context . API . GetTranslation ( "plugin_pluginsmanager_install_title" ) ,
162
+ Context . API . GetTranslation ( "plugin_pluginsmanager_install_title" ) ,
159
163
MessageBoxButton . YesNo , MessageBoxImage . Question ) == MessageBoxResult . Yes )
160
164
Context . API . RestartApp ( ) ;
161
165
}
162
166
163
167
internal List < Result > RequestUninstall ( string search )
164
168
{
169
+ if ( ! string . IsNullOrEmpty ( search )
170
+ && Settings . UninstallHotkey . StartsWith ( search )
171
+ && ( Settings . UninstallHotkey != search || ! search . StartsWith ( Settings . UninstallHotkey ) ) )
172
+ {
173
+ return
174
+ new List < Result >
175
+ {
176
+ new Result
177
+ {
178
+ Title = "Uninstall" ,
179
+ IcoPath = icoPath ,
180
+ SubTitle = "Select a plugin to uninstall" ,
181
+ Action = e =>
182
+ {
183
+ Context
184
+ . API
185
+ . ChangeQuery ( $ "{ Context . CurrentPluginMetadata . ActionKeywords . FirstOrDefault ( ) } { Settings . UninstallHotkey } ") ;
186
+
187
+ return false ;
188
+ }
189
+ }
190
+ } ;
191
+ }
192
+
193
+ var uninstallSearch = search . Replace ( Settings . UninstallHotkey , string . Empty ) . TrimStart ( ) ;
194
+
165
195
var results = Context . API
166
196
. GetAllPlugins ( )
167
197
. Select ( x =>
@@ -180,7 +210,7 @@ internal List<Result> RequestUninstall(string search)
180
210
} )
181
211
. ToList ( ) ;
182
212
183
- return Search ( results , search ) ;
213
+ return Search ( results , uninstallSearch ) ;
184
214
}
185
215
186
216
private void Uninstall ( PluginMetadata plugin )
0 commit comments