Skip to content

Commit a72750d

Browse files
committed
add plugin download behaviour
1 parent 8d96899 commit a72750d

File tree

4 files changed

+48
-33
lines changed

4 files changed

+48
-33
lines changed

Plugins/Flow.Launcher.Plugin.PluginManager/Flow.Launcher.Plugin.PluginsManager.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@
2929
</ItemGroup>
3030

3131
<ItemGroup>
32-
<Folder Include="Images\" />
32+
<Content Include="Images\**">
33+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
34+
</Content>
3335
</ItemGroup>
3436

3537
<ItemGroup>
36-
<Folder Include="Languages\" />
38+
<Content Include="Languages\**">
39+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
40+
</Content>
3741
</ItemGroup>
3842
</Project>

Plugins/Flow.Launcher.Plugin.PluginManager/Languages/en.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
xmlns:system="clr-namespace:System;assembly=mscorlib">
44

55
<!--Dialogues-->
6-
6+
<system:String x:Key="plugin_pluginsmanager_downloading_plugin">Downloading plugin</system:String>
7+
<system:String x:Key="plugin_pluginsmanager_please_wait">Please wait...</system:String>
8+
<system:String x:Key="plugin_pluginsmanager_download_success">Successfully downloaded</system:String>
79
<!--Controls-->
810

911
<!--Plugin Infos-->

Plugins/Flow.Launcher.Plugin.PluginManager/Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public List<Result> Query(Query query)
3939
{
4040
var search = query.Search;
4141

42-
var pluginManager = new PluginsManager();
42+
var pluginManager = new PluginsManager(Context);
4343

4444
return pluginManager.PluginsSearch(search);
4545
}
Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
using Flow.Launcher.Infrastructure;
1+
using Flow.Launcher.Infrastructure;
22
using Flow.Launcher.Infrastructure.Http;
3+
using Flow.Launcher.Infrastructure.Logger;
4+
using Flow.Launcher.Infrastructure.UserSettings;
35
using Flow.Launcher.Plugin.PluginsManager.Models;
46
using System;
57
using System.Collections.Generic;
8+
using System.IO;
69
using System.Linq;
710
using System.Net;
811
using System.Text;
12+
using System.Windows;
913

1014
namespace Flow.Launcher.Plugin.PluginsManager
1115
{
1216
internal class PluginsManager
1317
{
1418
private PluginsManifest pluginsManifest;
19+
private PluginInitContext context { get; set; }
1520

1621
private string icoPath = "Images\\plugin.png";
1722

18-
internal PluginsManager()
23+
internal PluginsManager(PluginInitContext context)
1924
{
2025
pluginsManifest = new PluginsManifest();
26+
this.context = context;
2127
}
2228
internal void PluginInstall(UserPlugin plugin)
2329
{
@@ -28,14 +34,28 @@ internal void PluginInstall(UserPlugin plugin)
2834
return;
2935
}
3036

31-
PluginDowload(plugin.UrlDownload, "");
37+
var filePath = Path.Combine(DataLocation.PluginsDirectory, $"{plugin.Name}{plugin.ID}.zip");
38+
PluginDownload(plugin.UrlDownload, filePath);
3239
}
3340

34-
private void PluginDowload(string downloadUrl, string toFilePath)
41+
private void PluginDownload(string downloadUrl, string toFilePath)
3542
{
36-
using (var wc = new WebClient { Proxy = Http.WebProxy() })
43+
try
3744
{
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");
3959
}
4060
}
4161

@@ -58,9 +78,8 @@ internal List<Result> PluginsSearch(string searchName)
5878
{
5979
var results = new List<Result>();
6080

61-
if (string.IsNullOrEmpty(searchName))
62-
{
63-
pluginsManifest.UserPlugins
81+
pluginsManifest
82+
.UserPlugins
6483
.ForEach(x => results.Add(
6584
new Result
6685
{
@@ -69,32 +88,22 @@ internal List<Result> PluginsSearch(string searchName)
6988
IcoPath = icoPath,
7089
Action = e =>
7190
{
91+
context.API.ShowMsg(context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
92+
context.API.GetTranslation("plugin_pluginsmanager_please_wait"));
93+
Application.Current.MainWindow.Hide();
7294
PluginInstall(x);
73-
return false;
95+
96+
return true;
7497
}
7598
}));
7699

100+
if (string.IsNullOrEmpty(searchName))
77101
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-
}));
96102

97-
return results;
103+
return results
104+
.Where(x => StringMatcher.FuzzySearch(searchName, x.Title).IsSearchPrecisionScoreMet())
105+
.Select(x => x)
106+
.ToList();
98107
}
99108
}
100109
}

0 commit comments

Comments
 (0)