@@ -15,14 +15,14 @@ namespace Flow.Launcher.Plugin.PluginsManager
15
15
internal class PluginsManager
16
16
{
17
17
private PluginsManifest pluginsManifest ;
18
- private PluginInitContext context { get ; set ; }
18
+ private PluginInitContext Context { get ; set ; }
19
19
20
20
private readonly string icoPath = "Images\\ plugin.png" ;
21
21
22
22
internal PluginsManager ( PluginInitContext context )
23
23
{
24
24
pluginsManifest = new PluginsManifest ( ) ;
25
- this . context = context ;
25
+ Context = context ;
26
26
}
27
27
internal void InstallOrUpdate ( UserPlugin plugin )
28
28
{
@@ -39,13 +39,13 @@ internal void InstallOrUpdate(UserPlugin plugin)
39
39
{
40
40
Utilities . Download ( plugin . UrlDownload , filePath ) ;
41
41
42
- context . API . ShowMsg ( context . API . GetTranslation ( "plugin_pluginsmanager_downloading_plugin" ) ,
43
- context . API . GetTranslation ( "plugin_pluginsmanager_download_success" ) ) ;
42
+ Context . API . ShowMsg ( Context . API . GetTranslation ( "plugin_pluginsmanager_downloading_plugin" ) ,
43
+ Context . API . GetTranslation ( "plugin_pluginsmanager_download_success" ) ) ;
44
44
}
45
45
catch ( Exception e )
46
46
{
47
- context . API . ShowMsg ( context . API . GetTranslation ( "plugin_pluginsmanager_downloading_plugin" ) ,
48
- context . API . GetTranslation ( "plugin_pluginsmanager_download_success" ) ) ;
47
+ Context . API . ShowMsg ( Context . API . GetTranslation ( "plugin_pluginsmanager_downloading_plugin" ) ,
48
+ Context . API . GetTranslation ( "plugin_pluginsmanager_download_success" ) ) ;
49
49
50
50
Log . Exception ( "PluginsManager" , "An error occured while downloading plugin" , e , "PluginDownload" ) ;
51
51
}
@@ -68,7 +68,18 @@ internal void PluginsManifestSiteOpen()
68
68
//Open https://git.vcmq.workers.dev/Flow-Launcher/Flow.Launcher.PluginsManifest
69
69
}
70
70
71
- internal List < Result > Search ( string searchName )
71
+ internal List < Result > Search ( List < Result > results , string searchName )
72
+ {
73
+ if ( string . IsNullOrEmpty ( searchName ) )
74
+ return results ;
75
+
76
+ return results
77
+ . Where ( x => StringMatcher . FuzzySearch ( searchName , x . Title ) . IsSearchPrecisionScoreMet ( ) )
78
+ . Select ( x => x )
79
+ . ToList ( ) ;
80
+ }
81
+
82
+ internal List < Result > RequestInstallOrUpdate ( string searchName )
72
83
{
73
84
var results = new List < Result > ( ) ;
74
85
@@ -82,22 +93,16 @@ internal List<Result> Search(string searchName)
82
93
IcoPath = icoPath ,
83
94
Action = e =>
84
95
{
85
- context . API . ShowMsg ( context . API . GetTranslation ( "plugin_pluginsmanager_downloading_plugin" ) ,
86
- context . API . GetTranslation ( "plugin_pluginsmanager_please_wait" ) ) ;
96
+ Context . API . ShowMsg ( Context . API . GetTranslation ( "plugin_pluginsmanager_downloading_plugin" ) ,
97
+ Context . API . GetTranslation ( "plugin_pluginsmanager_please_wait" ) ) ;
87
98
Application . Current . MainWindow . Hide ( ) ;
88
99
InstallOrUpdate ( x ) ;
89
100
90
101
return true ;
91
102
}
92
103
} ) ) ;
93
104
94
- if ( string . IsNullOrEmpty ( searchName ) )
95
- return results ;
96
-
97
- return results
98
- . Where ( x => StringMatcher . FuzzySearch ( searchName , x . Title ) . IsSearchPrecisionScoreMet ( ) )
99
- . Select ( x => x )
100
- . ToList ( ) ;
105
+ return Search ( results , searchName ) ;
101
106
}
102
107
103
108
private void Install ( UserPlugin plugin , string downloadedFilePath )
@@ -155,7 +160,7 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
155
160
$ "Version: { plugin . Version } { Environment . NewLine } " +
156
161
$ "Author: { plugin . Author } ";
157
162
158
- var existingPlugin = context . API . GetAllPlugins ( ) . Where ( x => x . Metadata . ID == plugin . ID ) . FirstOrDefault ( ) ;
163
+ var existingPlugin = Context . API . GetAllPlugins ( ) . Where ( x => x . Metadata . ID == plugin . ID ) . FirstOrDefault ( ) ;
159
164
160
165
if ( existingPlugin != null )
161
166
{
@@ -177,22 +182,56 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
177
182
178
183
Directory . Move ( pluginFolderPath , newPluginPath ) ;
179
184
180
- //exsiting plugins may be has loaded by application,
181
- //if we try to delelte those kind of plugins, we will get a error that indicate the
182
- //file is been used now.
183
- //current solution is to restart Flow Launcher. Ugly.
184
- //if (MainWindow.Initialized)
185
- //{
186
- // Plugins.Initialize();
187
- //}
188
185
if ( MessageBox . Show ( $ "You have installed plugin { plugin . Name } successfully.{ Environment . NewLine } " +
189
186
"Restart Flow Launcher to take effect?" ,
190
187
"Install plugin" , MessageBoxButton . YesNo , MessageBoxImage . Question ) == MessageBoxResult . Yes )
191
188
{
192
- context . API . RestartApp ( ) ;
189
+ Context . API . RestartApp ( ) ;
193
190
}
194
191
}
195
192
}
196
193
}
194
+
195
+ internal List < Result > RequestUninstall ( string search )
196
+ {
197
+ var results = new List < Result > ( ) ;
198
+
199
+ Context . API . GetAllPlugins ( )
200
+ . ForEach ( x => results . Add (
201
+ new Result
202
+ {
203
+ Title = $ "{ x . Metadata . Name } by { x . Metadata . Author } ",
204
+ SubTitle = x . Metadata . Description ,
205
+ IcoPath = icoPath ,
206
+ Action = e =>
207
+ {
208
+ Application . Current . MainWindow . Hide ( ) ;
209
+ Uninstall ( x . Metadata ) ;
210
+
211
+ return true ;
212
+ }
213
+ } ) ) ;
214
+
215
+ return Search ( results , search ) ;
216
+ }
217
+
218
+ private void Uninstall ( PluginMetadata plugin )
219
+ {
220
+ string message = Context . API . GetTranslation ( "plugin_pluginsmanager_uninstall_prompt" ) +
221
+ $ "{ Environment . NewLine } { Environment . NewLine } " +
222
+ $ "{ plugin . Name } by { plugin . Author } ";
223
+
224
+ if ( MessageBox . Show ( message , "Flow Launcher" , MessageBoxButton . YesNo ) == MessageBoxResult . Yes )
225
+ {
226
+ File . Create ( Path . Combine ( plugin . PluginDirectory , "NeedDelete.txt" ) ) . Close ( ) ;
227
+ var result = MessageBox . Show ( $ "You have uninstalled plugin { plugin . Name } successfully.{ Environment . NewLine } " +
228
+ "Restart Flow Launcher to take effect?" ,
229
+ "Install plugin" , MessageBoxButton . YesNo , MessageBoxImage . Question ) ;
230
+ if ( result == MessageBoxResult . Yes )
231
+ {
232
+ Context . API . RestartApp ( ) ;
233
+ }
234
+ }
235
+ }
197
236
}
198
237
}
0 commit comments