1
- using Flow . Launcher . Infrastructure ;
1
+ using Flow . Launcher . Infrastructure ;
2
2
using Flow . Launcher . Infrastructure . Http ;
3
+ using Flow . Launcher . Infrastructure . Logger ;
4
+ using Flow . Launcher . Infrastructure . UserSettings ;
3
5
using Flow . Launcher . Plugin . PluginsManager . Models ;
4
6
using System ;
5
7
using System . Collections . Generic ;
8
+ using System . IO ;
6
9
using System . Linq ;
7
10
using System . Net ;
8
11
using System . Text ;
12
+ using System . Windows ;
9
13
10
14
namespace Flow . Launcher . Plugin . PluginsManager
11
15
{
12
16
internal class PluginsManager
13
17
{
14
18
private PluginsManifest pluginsManifest ;
19
+ private PluginInitContext context { get ; set ; }
15
20
16
21
private string icoPath = "Images\\ plugin.png" ;
17
22
18
- internal PluginsManager ( )
23
+ internal PluginsManager ( PluginInitContext context )
19
24
{
20
25
pluginsManifest = new PluginsManifest ( ) ;
26
+ this . context = context ;
21
27
}
22
28
internal void PluginInstall ( UserPlugin plugin )
23
29
{
@@ -28,14 +34,28 @@ internal void PluginInstall(UserPlugin plugin)
28
34
return ;
29
35
}
30
36
31
- PluginDowload ( plugin . UrlDownload , "" ) ;
37
+ var filePath = Path . Combine ( DataLocation . PluginsDirectory , $ "{ plugin . Name } { plugin . ID } .zip") ;
38
+ PluginDownload ( plugin . UrlDownload , filePath ) ;
32
39
}
33
40
34
- private void PluginDowload ( string downloadUrl , string toFilePath )
41
+ private void PluginDownload ( string downloadUrl , string toFilePath )
35
42
{
36
- using ( var wc = new WebClient { Proxy = Http . WebProxy ( ) } )
43
+ try
37
44
{
38
- wc . DownloadFile ( downloadUrl , toFilePath ) ;
45
+ using ( var wc = new WebClient { Proxy = Http . WebProxy ( ) } )
46
+ {
47
+ wc . DownloadFile ( downloadUrl , toFilePath ) ;
48
+ }
49
+
50
+ context . API . ShowMsg ( context . API . GetTranslation ( "plugin_pluginsmanager_downloading_plugin" ) ,
51
+ context . API . GetTranslation ( "plugin_pluginsmanager_download_success" ) ) ;
52
+ }
53
+ catch ( Exception e )
54
+ {
55
+ context . API . ShowMsg ( context . API . GetTranslation ( "plugin_pluginsmanager_downloading_plugin" ) ,
56
+ context . API . GetTranslation ( "plugin_pluginsmanager_download_success" ) ) ;
57
+
58
+ Log . Exception ( "PluginsManager" , "An error occured while downloading plugin" , e , "PluginDownload" ) ;
39
59
}
40
60
}
41
61
@@ -58,9 +78,8 @@ internal List<Result> PluginsSearch(string searchName)
58
78
{
59
79
var results = new List < Result > ( ) ;
60
80
61
- if ( string . IsNullOrEmpty ( searchName ) )
62
- {
63
- pluginsManifest . UserPlugins
81
+ pluginsManifest
82
+ . UserPlugins
64
83
. ForEach ( x => results . Add (
65
84
new Result
66
85
{
@@ -69,32 +88,22 @@ internal List<Result> PluginsSearch(string searchName)
69
88
IcoPath = icoPath ,
70
89
Action = e =>
71
90
{
91
+ context . API . ShowMsg ( context . API . GetTranslation ( "plugin_pluginsmanager_downloading_plugin" ) ,
92
+ context . API . GetTranslation ( "plugin_pluginsmanager_please_wait" ) ) ;
93
+ Application . Current . MainWindow . Hide ( ) ;
72
94
PluginInstall ( x ) ;
73
- return false ;
95
+
96
+ return true ;
74
97
}
75
98
} ) ) ;
76
99
100
+ if ( string . IsNullOrEmpty ( searchName ) )
77
101
return results ;
78
- }
79
-
80
- pluginsManifest . UserPlugins
81
- . Where ( x => StringMatcher . FuzzySearch ( searchName , x . Name ) . IsSearchPrecisionScoreMet ( ) )
82
- . Select ( x => x )
83
- . ToList ( )
84
- . ForEach ( x => results . Add (
85
- new Result
86
- {
87
- Title = $ "{ x . Name } by { x . Author } ",
88
- SubTitle = x . Description ,
89
- IcoPath = icoPath ,
90
- Action = e =>
91
- {
92
- PluginInstall ( x ) ;
93
- return false ;
94
- }
95
- } ) ) ;
96
102
97
- return results ;
103
+ return results
104
+ . Where ( x => StringMatcher . FuzzySearch ( searchName , x . Title ) . IsSearchPrecisionScoreMet ( ) )
105
+ . Select ( x => x )
106
+ . ToList ( ) ;
98
107
}
99
108
}
100
109
}
0 commit comments