mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
Misc
1. Rename 2. Fix progress bar: progress bar should not be loaded when only white spaces typed
This commit is contained in:
@@ -17,7 +17,7 @@ namespace Wox.Plugin.PluginIndicator
|
|||||||
List<Result> results = new List<Result>();
|
List<Result> results = new List<Result>();
|
||||||
if (allPlugins.Count == 0)
|
if (allPlugins.Count == 0)
|
||||||
{
|
{
|
||||||
allPlugins = context.API.GetAllPlugins().Where(o => !PluginManager.IsSystemPlugin(o.Metadata)).ToList();
|
allPlugins = context.API.GetAllPlugins().Where(o => !PluginManager.IsGlobalPlugin(o.Metadata)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (PluginMetadata metadata in allPlugins.Select(o => o.Metadata))
|
foreach (PluginMetadata metadata in allPlugins.Select(o => o.Metadata))
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace Wox.Core.Plugin
|
|||||||
string content = string.Format(
|
string content = string.Format(
|
||||||
"Do you want to install following plugin?\r\n\r\nName: {0}\r\nVersion: {1}\r\nAuthor: {2}",
|
"Do you want to install following plugin?\r\n\r\nName: {0}\r\nVersion: {1}\r\nAuthor: {2}",
|
||||||
plugin.Name, plugin.Version, plugin.Author);
|
plugin.Name, plugin.Version, plugin.Author);
|
||||||
PluginPair existingPlugin = PluginManager.GetPlugin(plugin.ID);
|
PluginPair existingPlugin = PluginManager.GetPluginForId(plugin.ID);
|
||||||
|
|
||||||
if (existingPlugin != null)
|
if (existingPlugin != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ using Wox.Core.Exception;
|
|||||||
using Wox.Core.i18n;
|
using Wox.Core.i18n;
|
||||||
using Wox.Core.UI;
|
using Wox.Core.UI;
|
||||||
using Wox.Core.UserSettings;
|
using Wox.Core.UserSettings;
|
||||||
using Wox.Infrastructure;
|
|
||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||||
@@ -21,23 +20,19 @@ namespace Wox.Core.Plugin
|
|||||||
public static class PluginManager
|
public static class PluginManager
|
||||||
{
|
{
|
||||||
public const string DirectoryName = "Plugins";
|
public const string DirectoryName = "Plugins";
|
||||||
private static List<PluginMetadata> pluginMetadatas;
|
|
||||||
private static IEnumerable<PluginPair> instantQueryPlugins;
|
|
||||||
private static IEnumerable<PluginPair> exclusiveSearchPlugins;
|
|
||||||
private static IEnumerable<PluginPair> contextMenuPlugins;
|
private static IEnumerable<PluginPair> contextMenuPlugins;
|
||||||
private static List<PluginPair> plugins;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Directories that will hold Wox plugin directory
|
/// Directories that will hold Wox plugin directory
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static List<string> pluginDirectories = new List<string>();
|
private static List<string> pluginDirectories = new List<string>();
|
||||||
|
|
||||||
public static IEnumerable<PluginPair> AllPlugins
|
public static IEnumerable<PluginPair> AllPlugins { get; private set; }
|
||||||
{
|
|
||||||
get { return plugins; }
|
|
||||||
private set { plugins = value.OrderBy(o => o.Metadata.Name).ToList(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
private static List<PluginPair> GlobalPlugins { get; set; }
|
||||||
|
private static List<PluginPair> NonGlobalPlugins { get; set; }
|
||||||
|
|
||||||
|
private static IEnumerable<PluginPair> InstantQueryPlugins { get; set; }
|
||||||
public static IPublicAPI API { private set; get; }
|
public static IPublicAPI API { private set; get; }
|
||||||
|
|
||||||
public static string PluginDirectory
|
public static string PluginDirectory
|
||||||
@@ -79,9 +74,9 @@ namespace Wox.Core.Plugin
|
|||||||
SetupPluginDirectories();
|
SetupPluginDirectories();
|
||||||
API = api;
|
API = api;
|
||||||
|
|
||||||
pluginMetadatas = PluginConfig.Parse(pluginDirectories);
|
var metadatas = PluginConfig.Parse(pluginDirectories);
|
||||||
AllPlugins = (new CSharpPluginLoader().LoadPlugin(pluginMetadatas)).
|
AllPlugins = (new CSharpPluginLoader().LoadPlugin(metadatas)).
|
||||||
Concat(new JsonRPCPluginLoader<PythonPlugin>().LoadPlugin(pluginMetadatas));
|
Concat(new JsonRPCPluginLoader<PythonPlugin>().LoadPlugin(metadatas));
|
||||||
|
|
||||||
//load plugin i18n languages
|
//load plugin i18n languages
|
||||||
ResourceMerger.ApplyPluginLanguages();
|
ResourceMerger.ApplyPluginLanguages();
|
||||||
@@ -107,8 +102,21 @@ namespace Wox.Core.Plugin
|
|||||||
|
|
||||||
ThreadPool.QueueUserWorkItem(o =>
|
ThreadPool.QueueUserWorkItem(o =>
|
||||||
{
|
{
|
||||||
instantQueryPlugins = GetPlugins<IInstantQuery>();
|
InstantQueryPlugins = GetPluginsForInterface<IInstantQuery>();
|
||||||
contextMenuPlugins = GetPlugins<IContextMenu>();
|
contextMenuPlugins = GetPluginsForInterface<IContextMenu>();
|
||||||
|
GlobalPlugins = new List<PluginPair>();
|
||||||
|
NonGlobalPlugins = new List<PluginPair>();
|
||||||
|
foreach (var plugin in AllPlugins)
|
||||||
|
{
|
||||||
|
if (IsGlobalPlugin(plugin.Metadata))
|
||||||
|
{
|
||||||
|
GlobalPlugins.Add(plugin);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NonGlobalPlugins.Add(plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,18 +129,15 @@ namespace Wox.Core.Plugin
|
|||||||
{
|
{
|
||||||
// replace multiple white spaces with one white space
|
// replace multiple white spaces with one white space
|
||||||
var terms = text.Split(new[] { Query.TermSeperater }, StringSplitOptions.RemoveEmptyEntries);
|
var terms = text.Split(new[] { Query.TermSeperater }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
var rawQuery = string.Join(Query.TermSeperater, terms.ToArray());
|
var rawQuery = string.Join(Query.TermSeperater, terms);
|
||||||
var actionKeyword = string.Empty;
|
var actionKeyword = string.Empty;
|
||||||
var search = rawQuery;
|
var search = rawQuery;
|
||||||
IEnumerable<string> actionParameters = terms;
|
List<string> actionParameters = terms.ToList();
|
||||||
if (terms.Length == 0) return null;
|
if (terms.Length == 0) return null;
|
||||||
if (IsVailldActionKeyword(terms[0]))
|
if (IsVailldActionKeyword(terms[0]))
|
||||||
{
|
{
|
||||||
actionKeyword = terms[0];
|
actionKeyword = terms[0];
|
||||||
}
|
actionParameters = terms.Skip(1).ToList();
|
||||||
if (!string.IsNullOrEmpty(actionKeyword))
|
|
||||||
{
|
|
||||||
actionParameters = terms.Skip(1);
|
|
||||||
search = string.Join(Query.TermSeperater, actionParameters.ToArray());
|
search = string.Join(Query.TermSeperater, actionParameters.ToArray());
|
||||||
}
|
}
|
||||||
return new Query
|
return new Query
|
||||||
@@ -143,14 +148,14 @@ namespace Wox.Core.Plugin
|
|||||||
Search = search,
|
Search = search,
|
||||||
// Obsolete value initialisation
|
// Obsolete value initialisation
|
||||||
ActionName = actionKeyword,
|
ActionName = actionKeyword,
|
||||||
ActionParameters = actionParameters.ToList()
|
ActionParameters = actionParameters
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void QueryForAllPlugins(Query query)
|
public static void QueryForAllPlugins(Query query)
|
||||||
{
|
{
|
||||||
var pluginPairs = GetNonSystemPlugin(query) != null ?
|
var pluginPairs = GetPluginForActionKeyword(query.ActionKeyword) != null ?
|
||||||
new List<PluginPair> { GetNonSystemPlugin(query) } : GetSystemPlugins();
|
new List<PluginPair> { GetPluginForActionKeyword(query.ActionKeyword) } : GlobalPlugins;
|
||||||
foreach (var plugin in pluginPairs)
|
foreach (var plugin in pluginPairs)
|
||||||
{
|
{
|
||||||
var customizedPluginConfig = UserSettingStorage.Instance.
|
var customizedPluginConfig = UserSettingStorage.Instance.
|
||||||
@@ -200,7 +205,7 @@ namespace Wox.Core.Plugin
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static bool IsVailldActionKeyword(string actionKeyword)
|
private static bool IsVailldActionKeyword(string actionKeyword)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(actionKeyword) || actionKeyword == Query.WildcardSign) return false;
|
if (string.IsNullOrEmpty(actionKeyword) || actionKeyword == Query.GlobalPluginWildcardSign) return false;
|
||||||
PluginPair pair = AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeywords.Contains(actionKeyword));
|
PluginPair pair = AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeywords.Contains(actionKeyword));
|
||||||
if (pair == null) return false;
|
if (pair == null) return false;
|
||||||
var customizedPluginConfig = UserSettingStorage.Instance.
|
var customizedPluginConfig = UserSettingStorage.Instance.
|
||||||
@@ -208,9 +213,9 @@ namespace Wox.Core.Plugin
|
|||||||
return customizedPluginConfig == null || !customizedPluginConfig.Disabled;
|
return customizedPluginConfig == null || !customizedPluginConfig.Disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsSystemPlugin(PluginMetadata metadata)
|
public static bool IsGlobalPlugin(PluginMetadata metadata)
|
||||||
{
|
{
|
||||||
return metadata.ActionKeywords.Contains(Query.WildcardSign);
|
return metadata.ActionKeywords.Contains(Query.GlobalPluginWildcardSign);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsInstantQueryPlugin(PluginPair plugin)
|
private static bool IsInstantQueryPlugin(PluginPair plugin)
|
||||||
@@ -218,7 +223,7 @@ namespace Wox.Core.Plugin
|
|||||||
//any plugin that takes more than 200ms for AvgQueryTime won't be treated as IInstantQuery plugin anymore.
|
//any plugin that takes more than 200ms for AvgQueryTime won't be treated as IInstantQuery plugin anymore.
|
||||||
return plugin.AvgQueryTime < 200 &&
|
return plugin.AvgQueryTime < 200 &&
|
||||||
plugin.Plugin is IInstantQuery &&
|
plugin.Plugin is IInstantQuery &&
|
||||||
instantQueryPlugins.Any(p => p.Metadata.ID == plugin.Metadata.ID);
|
InstantQueryPlugins.Any(p => p.Metadata.ID == plugin.Metadata.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -226,29 +231,24 @@ namespace Wox.Core.Plugin
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static PluginPair GetPlugin(string id)
|
public static PluginPair GetPluginForId(string id)
|
||||||
{
|
{
|
||||||
return AllPlugins.FirstOrDefault(o => o.Metadata.ID == id);
|
return AllPlugins.FirstOrDefault(o => o.Metadata.ID == id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<PluginPair> GetPlugins<T>() where T : IFeatures
|
private static PluginPair GetPluginForActionKeyword(string actionKeyword)
|
||||||
|
{
|
||||||
|
//if a query doesn't contain a vaild action keyword, it should be a query for system plugin
|
||||||
|
if (string.IsNullOrEmpty(actionKeyword) || actionKeyword == Query.GlobalPluginWildcardSign) return null;
|
||||||
|
return NonGlobalPlugins.FirstOrDefault(o => o.Metadata.ActionKeywords.Contains(actionKeyword));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<PluginPair> GetPluginsForInterface<T>() where T : IFeatures
|
||||||
{
|
{
|
||||||
return AllPlugins.Where(p => p.Plugin is T);
|
return AllPlugins.Where(p => p.Plugin is T);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PluginPair GetNonSystemPlugin(Query query)
|
public static List<Result> GetContextMenusForPlugin(Result result)
|
||||||
{
|
|
||||||
//if a query doesn't contain a vaild action keyword, it should be a query for system plugin
|
|
||||||
if (string.IsNullOrEmpty(query.ActionKeyword)) return null;
|
|
||||||
return AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeywords.Contains(query.ActionKeyword));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<PluginPair> GetSystemPlugins()
|
|
||||||
{
|
|
||||||
return AllPlugins.Where(o => IsSystemPlugin(o.Metadata)).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<Result> GetPluginContextMenus(Result result)
|
|
||||||
{
|
{
|
||||||
var pluginPair = contextMenuPlugins.FirstOrDefault(o => o.Metadata.ID == result.PluginID);
|
var pluginPair = contextMenuPlugins.FirstOrDefault(o => o.Metadata.ID == result.PluginID);
|
||||||
var plugin = (IContextMenu)pluginPair?.Plugin;
|
var plugin = (IContextMenu)pluginPair?.Plugin;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace Wox.Core.UI
|
|||||||
internal static void ApplyPluginLanguages()
|
internal static void ApplyPluginLanguages()
|
||||||
{
|
{
|
||||||
RemoveResource(PluginManager.DirectoryName);
|
RemoveResource(PluginManager.DirectoryName);
|
||||||
foreach (var languageFile in PluginManager.GetPlugins<IPluginI18n>().
|
foreach (var languageFile in PluginManager.GetPluginsForInterface<IPluginI18n>().
|
||||||
Select(plugin => InternationalizationManager.Instance.GetLanguageFile(((IPluginI18n)plugin.Plugin).GetLanguagesFolder())).
|
Select(plugin => InternationalizationManager.Instance.GetLanguageFile(((IPluginI18n)plugin.Plugin).GetLanguagesFolder())).
|
||||||
Where(file => !string.IsNullOrEmpty(file)))
|
Where(file => !string.IsNullOrEmpty(file)))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,13 +25,19 @@ namespace Wox.Plugin
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal string[] Terms { private get; set; }
|
internal string[] Terms { private get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query can be splited into multiple terms by whitespace
|
||||||
|
/// </summary>
|
||||||
public const string TermSeperater = " ";
|
public const string TermSeperater = " ";
|
||||||
|
/// <summary>
|
||||||
|
/// User can set multiple action keywords seperated by ';'
|
||||||
|
/// </summary>
|
||||||
public const string ActionKeywordSeperater = ";";
|
public const string ActionKeywordSeperater = ";";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// * is used for System Plugin
|
/// '*' is used for System Plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string WildcardSign = "*";
|
public const string GlobalPluginWildcardSign = "*";
|
||||||
|
|
||||||
public string ActionKeyword { get; set; }
|
public string ActionKeyword { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace Wox
|
|||||||
public ActionKeywords(string pluginId)
|
public ActionKeywords(string pluginId)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
PluginPair plugin = PluginManager.GetPlugin(pluginId);
|
PluginPair plugin = PluginManager.GetPluginForId(pluginId);
|
||||||
if (plugin == null)
|
if (plugin == null)
|
||||||
{
|
{
|
||||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("cannotFindSpecifiedPlugin"));
|
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("cannotFindSpecifiedPlugin"));
|
||||||
@@ -47,7 +47,7 @@ namespace Wox
|
|||||||
|
|
||||||
var actionKeywords = tbAction.Text.Trim().Split(new[] { Query.ActionKeywordSeperater }, StringSplitOptions.RemoveEmptyEntries).ToArray();
|
var actionKeywords = tbAction.Text.Trim().Split(new[] { Query.ActionKeywordSeperater }, StringSplitOptions.RemoveEmptyEntries).ToArray();
|
||||||
//check new action keyword didn't used by other plugin
|
//check new action keyword didn't used by other plugin
|
||||||
if (actionKeywords[0] != Query.WildcardSign && PluginManager.AllPlugins.
|
if (actionKeywords[0] != Query.GlobalPluginWildcardSign && PluginManager.AllPlugins.
|
||||||
SelectMany(p => p.Metadata.ActionKeywords).
|
SelectMany(p => p.Metadata.ActionKeywords).
|
||||||
Any(k => actionKeywords.Contains(k)))
|
Any(k => actionKeywords.Contains(k)))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -464,7 +464,7 @@ namespace Wox
|
|||||||
Query(tbQuery.Text);
|
Query(tbQuery.Text);
|
||||||
Dispatcher.DelayInvoke("ShowProgressbar", () =>
|
Dispatcher.DelayInvoke("ShowProgressbar", () =>
|
||||||
{
|
{
|
||||||
if (!queryHasReturn && !string.IsNullOrEmpty(tbQuery.Text) && tbQuery.Text != lastQuery)
|
if (!string.IsNullOrEmpty(tbQuery.Text.Trim()) && tbQuery.Text != lastQuery && !queryHasReturn)
|
||||||
{
|
{
|
||||||
StartProgress();
|
StartProgress();
|
||||||
}
|
}
|
||||||
@@ -873,10 +873,10 @@ namespace Wox
|
|||||||
|
|
||||||
private void ShowContextMenu(Result result)
|
private void ShowContextMenu(Result result)
|
||||||
{
|
{
|
||||||
List<Result> results = PluginManager.GetPluginContextMenus(result);
|
List<Result> results = PluginManager.GetContextMenusForPlugin(result);
|
||||||
results.ForEach(o =>
|
results.ForEach(o =>
|
||||||
{
|
{
|
||||||
o.PluginDirectory = PluginManager.GetPlugin(result.PluginID).Metadata.PluginDirectory;
|
o.PluginDirectory = PluginManager.GetPluginForId(result.PluginID).Metadata.PluginDirectory;
|
||||||
o.PluginID = result.PluginID;
|
o.PluginID = result.PluginID;
|
||||||
o.OriginQuery = result.OriginQuery;
|
o.OriginQuery = result.OriginQuery;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -605,7 +605,7 @@ namespace Wox
|
|||||||
string id = pair.Metadata.ID;
|
string id = pair.Metadata.ID;
|
||||||
ActionKeywords changeKeywordsWindow = new ActionKeywords(id);
|
ActionKeywords changeKeywordsWindow = new ActionKeywords(id);
|
||||||
changeKeywordsWindow.ShowDialog();
|
changeKeywordsWindow.ShowDialog();
|
||||||
PluginPair plugin = PluginManager.GetPlugin(id);
|
PluginPair plugin = PluginManager.GetPluginForId(id);
|
||||||
if (plugin != null) pluginActionKeywords.Text = string.Join(Query.ActionKeywordSeperater, pair.Metadata.ActionKeywords);
|
if (plugin != null) pluginActionKeywords.Text = string.Join(Query.ActionKeywordSeperater, pair.Metadata.ActionKeywords);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user