mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
add plugin search
This commit is contained in:
parent
cc1d049cad
commit
1587010126
5 changed files with 83 additions and 28 deletions
|
|
@ -37,7 +37,11 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
return new List<Result>();
|
||||
var search = query.Search;
|
||||
|
||||
var pluginManager = new PluginsManager();
|
||||
|
||||
return pluginManager.PluginsSearch(search);
|
||||
}
|
||||
|
||||
public void Save()
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Flow.Launcher.Plugin.PluginsManager.Models
|
||||
{
|
||||
internal class Plugin
|
||||
{
|
||||
internal string ID { get; set; }
|
||||
internal string Name { get; set; }
|
||||
internal string Description { get; set; }
|
||||
internal string Author { get; set; }
|
||||
internal string Version { get; set; }
|
||||
internal string Language { get; set; }
|
||||
internal string Website { get; set; }
|
||||
internal string UrlDownload { get; set; }
|
||||
internal string UrlSourceCode { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -8,10 +8,10 @@ using System.Text;
|
|||
|
||||
namespace Flow.Launcher.Plugin.PluginsManager.Models
|
||||
{
|
||||
class PluginsManifest
|
||||
internal class PluginsManifest
|
||||
{
|
||||
public List<Plugin> Plugins { get; private set; }
|
||||
public PluginsManifest()
|
||||
internal List<UserPlugin> UserPlugins { get; private set; }
|
||||
internal PluginsManifest()
|
||||
{
|
||||
var json = string.Empty;
|
||||
|
||||
|
|
@ -25,11 +25,11 @@ namespace Flow.Launcher.Plugin.PluginsManager.Models
|
|||
{
|
||||
Log.Exception("|PluginManagement.GetManifest|Encountered error trying to download plugins manifest", e);
|
||||
|
||||
Plugins = new List<Plugin>();
|
||||
UserPlugins = new List<UserPlugin>();
|
||||
}
|
||||
}
|
||||
|
||||
Plugins = !string.IsNullOrEmpty(json) ? JsonConvert.DeserializeObject<List<Plugin>>(json) : new List<Plugin>();
|
||||
UserPlugins = !string.IsNullOrEmpty(json) ? JsonConvert.DeserializeObject<List<UserPlugin>>(json) : new List<UserPlugin>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Flow.Launcher.Plugin.PluginsManager.Models
|
||||
{
|
||||
public class UserPlugin
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Author { get; set; }
|
||||
public string Version { get; set; }
|
||||
public string Language { get; set; }
|
||||
public string Website { get; set; }
|
||||
public string UrlDownload { get; set; }
|
||||
public string UrlSourceCode { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
using Flow.Launcher.Infrastructure.Http;
|
||||
using Flow.Launcher.Infrastructure;
|
||||
using Flow.Launcher.Infrastructure.Http;
|
||||
using Flow.Launcher.Plugin.PluginsManager.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
|
|
@ -8,7 +11,12 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
{
|
||||
internal class PluginsManager
|
||||
{
|
||||
internal void PluginInstall(Plugin plugin)
|
||||
private PluginsManifest pluginsManifest;
|
||||
internal PluginsManager()
|
||||
{
|
||||
pluginsManifest = new PluginsManifest();
|
||||
}
|
||||
internal void PluginInstall(UserPlugin plugin)
|
||||
{
|
||||
if (PluginExists())
|
||||
{
|
||||
|
|
@ -17,7 +25,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
return;
|
||||
}
|
||||
|
||||
PluginDowload(plugin.Url, "");
|
||||
PluginDowload(plugin.UrlDownload, "");
|
||||
}
|
||||
|
||||
private void PluginDowload(string downloadUrl, string toFilePath)
|
||||
|
|
@ -42,5 +50,48 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
internal List<Result> PluginsSearch(string searchName)
|
||||
{
|
||||
var results = new List<Result>();
|
||||
|
||||
if (string.IsNullOrEmpty(searchName))
|
||||
{
|
||||
pluginsManifest.UserPlugins
|
||||
.ForEach(x => results.Add(
|
||||
new Result
|
||||
{
|
||||
Title = $"{x.Name} by {x.Author}",
|
||||
SubTitle = x.Description,
|
||||
IcoPath = "Images\\plugin.png",
|
||||
Action = e =>
|
||||
{
|
||||
PluginInstall(x);
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
|
||||
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 = "Images\\plugin.png",
|
||||
Action = e =>
|
||||
{
|
||||
PluginInstall(x);
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue