mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Implement IInstantSearch for CMD and WebSearch plugin
This commit is contained in:
parent
4ecff94aec
commit
9f64a384d6
7 changed files with 99 additions and 13 deletions
|
|
@ -6,12 +6,13 @@ using System.Reflection;
|
|||
using System.Windows.Forms;
|
||||
using WindowsInput;
|
||||
using WindowsInput.Native;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Hotkey;
|
||||
using Control = System.Windows.Controls.Control;
|
||||
|
||||
namespace Wox.Plugin.CMD
|
||||
{
|
||||
public class CMD : IPlugin, ISettingProvider, IPluginI18n
|
||||
public class CMD : IPlugin, ISettingProvider, IPluginI18n, IInstantSearch
|
||||
{
|
||||
private PluginInitContext context;
|
||||
private bool WinRStroked;
|
||||
|
|
@ -37,6 +38,7 @@ namespace Wox.Plugin.CMD
|
|||
context.API.PushResults(query, context.CurrentPluginMetadata, history);
|
||||
pushedResults.AddRange(history);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
string basedir = null;
|
||||
|
|
@ -72,6 +74,7 @@ namespace Wox.Plugin.CMD
|
|||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
|
@ -207,5 +210,11 @@ namespace Wox.Plugin.CMD
|
|||
{
|
||||
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages");
|
||||
}
|
||||
|
||||
public bool IsInstantSearch(string query)
|
||||
{
|
||||
if (query.StartsWith(">")) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ using Wox.Plugin.WebSearch.SuggestionSources;
|
|||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
public class WebSearchPlugin : IPlugin, ISettingProvider,IPluginI18n
|
||||
public class WebSearchPlugin : IPlugin, ISettingProvider, IPluginI18n, IInstantSearch
|
||||
{
|
||||
private PluginInitContext context;
|
||||
|
||||
|
|
@ -97,5 +97,16 @@ namespace Wox.Plugin.WebSearch
|
|||
{
|
||||
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages");
|
||||
}
|
||||
|
||||
public bool IsInstantSearch(string query)
|
||||
{
|
||||
var strings = query.Split(' ');
|
||||
if (strings.Length > 1)
|
||||
{
|
||||
return WebSearchStorage.Instance.EnableWebSearchSuggestion &&
|
||||
WebSearchStorage.Instance.WebSearches.Exists(o => o.ActionWord == strings[0] && o.Enabled);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@ namespace Wox.Core.Plugin
|
|||
public static class PluginManager
|
||||
{
|
||||
public const string ActionKeywordWildcardSign = "*";
|
||||
private static List<PluginMetadata> pluginMetadatas;
|
||||
private static List<IInstantSearch> instantSearches = new List<IInstantSearch>();
|
||||
|
||||
|
||||
public static String DebuggerMode { get; private set; }
|
||||
public static IPublicAPI API { get; private set; }
|
||||
|
|
@ -31,7 +34,6 @@ namespace Wox.Core.Plugin
|
|||
/// </summary>
|
||||
private static List<string> pluginDirectories = new List<string>();
|
||||
|
||||
|
||||
private static void SetupPluginDirectories()
|
||||
{
|
||||
pluginDirectories.Add(PluginDirectory);
|
||||
|
|
@ -72,7 +74,7 @@ namespace Wox.Core.Plugin
|
|||
API = api;
|
||||
plugins.Clear();
|
||||
|
||||
List<PluginMetadata> pluginMetadatas = PluginConfig.Parse(pluginDirectories);
|
||||
pluginMetadatas = PluginConfig.Parse(pluginDirectories);
|
||||
plugins.AddRange(new CSharpPluginLoader().LoadPlugin(pluginMetadatas));
|
||||
plugins.AddRange(new JsonRPCPluginLoader<PythonPlugin>().LoadPlugin(pluginMetadatas));
|
||||
|
||||
|
|
@ -95,6 +97,8 @@ namespace Wox.Core.Plugin
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
LoadInstantSearches();
|
||||
}
|
||||
|
||||
public static void InstallPlugin(string path)
|
||||
|
|
@ -140,6 +144,46 @@ namespace Wox.Core.Plugin
|
|||
DebuggerMode = path;
|
||||
}
|
||||
|
||||
public static bool IsInstantSearch(string query)
|
||||
{
|
||||
return LoadInstantSearches().Any(o => o.IsInstantSearch(query));
|
||||
}
|
||||
|
||||
private static List<IInstantSearch> LoadInstantSearches()
|
||||
{
|
||||
if (instantSearches.Count > 0) return instantSearches;
|
||||
List<PluginMetadata> CSharpPluginMetadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList();
|
||||
|
||||
foreach (PluginMetadata metadata in CSharpPluginMetadatas)
|
||||
{
|
||||
try
|
||||
{
|
||||
Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
|
||||
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IInstantSearch))).ToList();
|
||||
if (types.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (Type type in types)
|
||||
{
|
||||
instantSearches.Add(Activator.CreateInstance(type) as IInstantSearch);
|
||||
}
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Log.Error(string.Format("Couldn't load plugin {0}: {1}", metadata.Name, e.Message));
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return instantSearches;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get specified plugin, return null if not found
|
||||
/// </summary>
|
||||
|
|
|
|||
12
Wox.Plugin/IInstantSearch.cs
Normal file
12
Wox.Plugin/IInstantSearch.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Wox.Plugin
|
||||
{
|
||||
public interface IInstantSearch
|
||||
{
|
||||
bool IsInstantSearch(string query);
|
||||
}
|
||||
}
|
||||
|
|
@ -17,4 +17,4 @@ using System.Runtime.InteropServices;
|
|||
|
||||
[assembly: InternalsVisibleTo("Wox")]
|
||||
[assembly: InternalsVisibleTo("Wox.Core")]
|
||||
[assembly: InternalsVisibleTo("Wox.Test")]
|
||||
[assembly: InternalsVisibleTo("Wox.Test")]
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="AllowedLanguage.cs" />
|
||||
<Compile Include="EventHandler.cs" />
|
||||
<Compile Include="IInstantSearch.cs" />
|
||||
<Compile Include="IHttpProxy.cs" />
|
||||
<Compile Include="IPluginI18n.cs" />
|
||||
<Compile Include="IPlugin.cs" />
|
||||
|
|
|
|||
|
|
@ -337,18 +337,27 @@ namespace Wox
|
|||
if (pnlResult.Dirty) pnlResult.Clear();
|
||||
}, TimeSpan.FromMilliseconds(100), null);
|
||||
queryHasReturn = false;
|
||||
var q = new Query(lastQuery);
|
||||
FireBeforeWoxQueryEvent(q);
|
||||
Query(q);
|
||||
Query query = new Query(lastQuery);
|
||||
FireBeforeWoxQueryEvent(query);
|
||||
Query(query);
|
||||
Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
|
||||
{
|
||||
if (!queryHasReturn && originQuery == lastQuery && !string.IsNullOrEmpty(lastQuery))
|
||||
if (!queryHasReturn && originQuery == tbQuery.Text && !string.IsNullOrEmpty(lastQuery))
|
||||
{
|
||||
StartProgress();
|
||||
}
|
||||
}, TimeSpan.FromMilliseconds(150), lastQuery);
|
||||
FireAfterWoxQueryEvent(q);
|
||||
}, TimeSpan.FromMilliseconds(200));
|
||||
}, TimeSpan.FromMilliseconds(150), tbQuery.Text);
|
||||
FireAfterWoxQueryEvent(query);
|
||||
}, TimeSpan.FromMilliseconds(GetSearchDelay(lastQuery)));
|
||||
}
|
||||
|
||||
private int GetSearchDelay(string query)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(query) && PluginManager.IsInstantSearch(query))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 200;
|
||||
}
|
||||
|
||||
private void FireAfterWoxQueryEvent(Query q)
|
||||
|
|
|
|||
Loading…
Reference in a new issue