mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Refactoring.
This commit is contained in:
@@ -15,7 +15,7 @@ namespace Wox.CommandArgs
|
||||
|
||||
public void Execute(IList<string> args)
|
||||
{
|
||||
PluginManager.Init();
|
||||
PluginManager.Init(App.Window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Commands
|
||||
{
|
||||
public abstract class BaseCommand
|
||||
{
|
||||
public abstract void Dispatch(Query query);
|
||||
|
||||
protected void UpdateResultView(List<Result> results)
|
||||
{
|
||||
App.Window.OnUpdateResultView(results);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Helper;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Commands
|
||||
{
|
||||
internal static class CommandFactory
|
||||
{
|
||||
private static PluginCommand pluginCmd = new PluginCommand();
|
||||
private static SystemCommand systemCmd = new SystemCommand();
|
||||
|
||||
public static void DispatchCommand(Query query)
|
||||
{
|
||||
if (PluginManager.HitThirdpartyKeyword(query))
|
||||
{
|
||||
pluginCmd.Dispatch(query);
|
||||
}
|
||||
else
|
||||
{
|
||||
systemCmd.Dispatch(query);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Helper;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Commands
|
||||
{
|
||||
public class PluginCommand : BaseCommand
|
||||
{
|
||||
public override void Dispatch(Query query)
|
||||
{
|
||||
PluginPair thirdPlugin = PluginManager.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.ActionName);
|
||||
if (thirdPlugin != null && !string.IsNullOrEmpty(thirdPlugin.Metadata.ActionKeyword))
|
||||
{
|
||||
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == thirdPlugin.Metadata.ID);
|
||||
if (customizedPluginConfig != null && customizedPluginConfig.Disabled)
|
||||
{
|
||||
//need to stop the loading animation
|
||||
UpdateResultView(null);
|
||||
return;
|
||||
}
|
||||
|
||||
ThreadPool.QueueUserWorkItem(t =>
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Result> results = thirdPlugin.Plugin.Query(query) ?? new List<Result>();
|
||||
App.Window.PushResults(query,thirdPlugin.Metadata,results);
|
||||
}
|
||||
catch (Exception queryException)
|
||||
{
|
||||
Log.Error(string.Format("Plugin {0} query failed: {1}", thirdPlugin.Metadata.Name,
|
||||
queryException.Message));
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.SystemPlugins;
|
||||
|
||||
namespace Wox.Commands
|
||||
{
|
||||
public class SystemCommand : BaseCommand
|
||||
{
|
||||
private IEnumerable<PluginPair> allSytemPlugins = PluginManager.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System);
|
||||
|
||||
public override void Dispatch(Query query)
|
||||
{
|
||||
var queryPlugins = allSytemPlugins;
|
||||
if (UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == query.ActionName && o.Enabled))
|
||||
{
|
||||
//websearch mode
|
||||
queryPlugins = new List<PluginPair>()
|
||||
{
|
||||
allSytemPlugins.First(o => ((ISystemPlugin)o.Plugin).ID == "565B73353DBF4806919830B9202EE3BF")
|
||||
};
|
||||
}
|
||||
|
||||
foreach (PluginPair pair in queryPlugins)
|
||||
{
|
||||
PluginPair pair1 = pair;
|
||||
ThreadPool.QueueUserWorkItem(state =>
|
||||
{
|
||||
List<Result> results = pair1.Plugin.Query(query);
|
||||
results.ForEach(o => { o.AutoAjustScore = true; });
|
||||
|
||||
App.Window.PushResults(query, pair1.Metadata, results);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ namespace Wox.Helper
|
||||
try
|
||||
{
|
||||
metadata = JsonConvert.DeserializeObject<PluginMetadata>(File.ReadAllText(configPath));
|
||||
metadata.PluginType = PluginType.ThirdParty;
|
||||
metadata.PluginType = PluginType.User;
|
||||
metadata.PluginDirectory = pluginDirectory;
|
||||
}
|
||||
catch (Exception)
|
||||
|
||||
@@ -9,8 +9,8 @@ namespace Wox.ImageLoader
|
||||
[Serializable]
|
||||
public class ImageCacheStroage : BinaryStorage<ImageCacheStroage>
|
||||
{
|
||||
public int counter = 0;
|
||||
public const int maxCached = 200;
|
||||
private int counter = 0;
|
||||
private const int maxCached = 200;
|
||||
public Dictionary<string, int> TopUsedImages = new Dictionary<string, int>();
|
||||
|
||||
protected override string ConfigName
|
||||
|
||||
@@ -14,7 +14,6 @@ using WindowsInput;
|
||||
using WindowsInput.Native;
|
||||
using NHotkey;
|
||||
using NHotkey.Wpf;
|
||||
using Wox.Commands;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Helper;
|
||||
using Wox.Infrastructure;
|
||||
@@ -22,6 +21,7 @@ using Wox.Infrastructure.Hotkey;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
using Wox.Plugin;
|
||||
using Wox.Storage;
|
||||
using Wox.Update;
|
||||
using Application = System.Windows.Application;
|
||||
using Brushes = System.Windows.Media.Brushes;
|
||||
@@ -127,7 +127,7 @@ namespace Wox
|
||||
|
||||
public void ReloadPlugins()
|
||||
{
|
||||
Dispatcher.Invoke(new Action(PluginManager.Init));
|
||||
Dispatcher.Invoke(new Action(()=> PluginManager.Init(this)));
|
||||
}
|
||||
|
||||
public List<PluginPair> GetAllPlugins()
|
||||
@@ -192,7 +192,7 @@ namespace Wox
|
||||
ThreadPool.QueueUserWorkItem(o =>
|
||||
{
|
||||
Thread.Sleep(50);
|
||||
PluginManager.Init();
|
||||
PluginManager.Init(this);
|
||||
});
|
||||
ThreadPool.QueueUserWorkItem(o =>
|
||||
{
|
||||
@@ -357,9 +357,9 @@ namespace Wox
|
||||
}, TimeSpan.FromMilliseconds(100), null);
|
||||
queryHasReturn = false;
|
||||
var q = new Query(lastQuery);
|
||||
CommandFactory.DispatchCommand(q);
|
||||
PluginManager.Query(q);
|
||||
BackToResultMode();
|
||||
if (PluginManager.HitThirdpartyKeyword(q))
|
||||
if (PluginManager.IsUserPluginQuery(q))
|
||||
{
|
||||
Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
|
||||
{
|
||||
|
||||
@@ -195,7 +195,7 @@ namespace Wox
|
||||
new CollectionContainer
|
||||
{
|
||||
Collection =
|
||||
PluginManager.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.ThirdParty)
|
||||
PluginManager.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.User)
|
||||
}
|
||||
};
|
||||
lbPlugins.ItemsSource = plugins;
|
||||
|
||||
40
Wox/Storage/UserSelectedRecordStorage.cs
Normal file
40
Wox/Storage/UserSelectedRecordStorage.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Storage
|
||||
{
|
||||
public class UserSelectedRecordStorage : JsonStrorage<UserSelectedRecordStorage>
|
||||
{
|
||||
[JsonProperty]
|
||||
private Dictionary<string, int> records = new Dictionary<string, int>();
|
||||
|
||||
protected override string ConfigName
|
||||
{
|
||||
get { return "UserSelectedRecords"; }
|
||||
}
|
||||
|
||||
public void Add(Result result)
|
||||
{
|
||||
if (records.ContainsKey(result.ToString()))
|
||||
{
|
||||
records[result.ToString()] += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
records.Add(result.ToString(), 1);
|
||||
}
|
||||
Save();
|
||||
}
|
||||
|
||||
public int GetSelectedCount(Result result)
|
||||
{
|
||||
if (records.ContainsKey(result.ToString()))
|
||||
{
|
||||
return records[result.ToString()];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ImageLoader\ImageCacheStroage.cs" />
|
||||
<Compile Include="Storage\UserSelectedRecordStorage.cs" />
|
||||
<Compile Include="Update\NewVersionWindow.xaml.cs">
|
||||
<DependentUpon>NewVersionWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@@ -124,10 +125,6 @@
|
||||
<Compile Include="CommandArgs\PluginDebuggerCommandArg.cs" />
|
||||
<Compile Include="CommandArgs\QueryCommandArg.cs" />
|
||||
<Compile Include="CommandArgs\ReloadPluginCommandArg.cs" />
|
||||
<Compile Include="Commands\BaseCommand.cs" />
|
||||
<Compile Include="Commands\CommandFactory.cs" />
|
||||
<Compile Include="Commands\PluginCommand.cs" />
|
||||
<Compile Include="Commands\SystemCommand.cs" />
|
||||
<Compile Include="Converters\AsyncConverter.cs" />
|
||||
<Compile Include="Converters\ConvertorBase.cs" />
|
||||
<Compile Include="Helper\DataWebRequestFactory.cs" />
|
||||
|
||||
Reference in New Issue
Block a user