mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
add plugin download behaviour
This commit is contained in:
parent
8d96899a82
commit
a72750dc65
4 changed files with 48 additions and 33 deletions
|
|
@ -29,10 +29,14 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Images\" />
|
||||
<Content Include="Images\**">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Languages\" />
|
||||
<Content Include="Languages\**">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -3,7 +3,9 @@
|
|||
xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||
|
||||
<!--Dialogues-->
|
||||
|
||||
<system:String x:Key="plugin_pluginsmanager_downloading_plugin">Downloading plugin</system:String>
|
||||
<system:String x:Key="plugin_pluginsmanager_please_wait">Please wait...</system:String>
|
||||
<system:String x:Key="plugin_pluginsmanager_download_success">Successfully downloaded</system:String>
|
||||
<!--Controls-->
|
||||
|
||||
<!--Plugin Infos-->
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
{
|
||||
var search = query.Search;
|
||||
|
||||
var pluginManager = new PluginsManager();
|
||||
var pluginManager = new PluginsManager(Context);
|
||||
|
||||
return pluginManager.PluginsSearch(search);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,29 @@
|
|||
using Flow.Launcher.Infrastructure;
|
||||
using Flow.Launcher.Infrastructure;
|
||||
using Flow.Launcher.Infrastructure.Http;
|
||||
using Flow.Launcher.Infrastructure.Logger;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.Plugin.PluginsManager.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
|
||||
namespace Flow.Launcher.Plugin.PluginsManager
|
||||
{
|
||||
internal class PluginsManager
|
||||
{
|
||||
private PluginsManifest pluginsManifest;
|
||||
private PluginInitContext context { get; set; }
|
||||
|
||||
private string icoPath = "Images\\plugin.png";
|
||||
|
||||
internal PluginsManager()
|
||||
internal PluginsManager(PluginInitContext context)
|
||||
{
|
||||
pluginsManifest = new PluginsManifest();
|
||||
this.context = context;
|
||||
}
|
||||
internal void PluginInstall(UserPlugin plugin)
|
||||
{
|
||||
|
|
@ -28,14 +34,28 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
return;
|
||||
}
|
||||
|
||||
PluginDowload(plugin.UrlDownload, "");
|
||||
var filePath = Path.Combine(DataLocation.PluginsDirectory, $"{plugin.Name}{plugin.ID}.zip");
|
||||
PluginDownload(plugin.UrlDownload, filePath);
|
||||
}
|
||||
|
||||
private void PluginDowload(string downloadUrl, string toFilePath)
|
||||
private void PluginDownload(string downloadUrl, string toFilePath)
|
||||
{
|
||||
using (var wc = new WebClient { Proxy = Http.WebProxy() })
|
||||
try
|
||||
{
|
||||
wc.DownloadFile(downloadUrl, toFilePath);
|
||||
using (var wc = new WebClient { Proxy = Http.WebProxy() })
|
||||
{
|
||||
wc.DownloadFile(downloadUrl, toFilePath);
|
||||
}
|
||||
|
||||
context.API.ShowMsg(context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
|
||||
context.API.GetTranslation("plugin_pluginsmanager_download_success"));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
context.API.ShowMsg(context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
|
||||
context.API.GetTranslation("plugin_pluginsmanager_download_success"));
|
||||
|
||||
Log.Exception("PluginsManager", "An error occured while downloading plugin", e, "PluginDownload");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -58,9 +78,8 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
{
|
||||
var results = new List<Result>();
|
||||
|
||||
if (string.IsNullOrEmpty(searchName))
|
||||
{
|
||||
pluginsManifest.UserPlugins
|
||||
pluginsManifest
|
||||
.UserPlugins
|
||||
.ForEach(x => results.Add(
|
||||
new Result
|
||||
{
|
||||
|
|
@ -69,32 +88,22 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
IcoPath = icoPath,
|
||||
Action = e =>
|
||||
{
|
||||
context.API.ShowMsg(context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
|
||||
context.API.GetTranslation("plugin_pluginsmanager_please_wait"));
|
||||
Application.Current.MainWindow.Hide();
|
||||
PluginInstall(x);
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}));
|
||||
|
||||
if (string.IsNullOrEmpty(searchName))
|
||||
return results;
|
||||
}
|
||||
|
||||
pluginsManifest.UserPlugins
|
||||
.Where(x => StringMatcher.FuzzySearch(searchName, x.Name).IsSearchPrecisionScoreMet())
|
||||
.Select(x => x)
|
||||
.ToList()
|
||||
.ForEach(x => results.Add(
|
||||
new Result
|
||||
{
|
||||
Title = $"{x.Name} by {x.Author}",
|
||||
SubTitle = x.Description,
|
||||
IcoPath = icoPath,
|
||||
Action = e =>
|
||||
{
|
||||
PluginInstall(x);
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
|
||||
return results;
|
||||
return results
|
||||
.Where(x => StringMatcher.FuzzySearch(searchName, x.Title).IsSearchPrecisionScoreMet())
|
||||
.Select(x => x)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue