mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Rearrange query execution order
1. remove usage of PushResult 2. rearrange query execution order 3. decouple UserSetting dependency 4. remove instant query 5. remove backkeydown event 6. part of #389
This commit is contained in:
@@ -47,11 +47,14 @@ namespace Wox
|
||||
ThreadPool.SetMinThreads(10, 5);
|
||||
ThreadPool.QueueUserWorkItem(_ => { ImageLoader.ImageLoader.PreloadImages(); });
|
||||
|
||||
MainViewModel mainVM = new MainViewModel();
|
||||
PluginManager.Initialize();
|
||||
UserSettingStorage settings = UserSettingStorage.Instance;
|
||||
MainViewModel mainVM = new MainViewModel(settings);
|
||||
API = new PublicAPIInstance(mainVM);
|
||||
PluginManager.InitializePlugins(API);
|
||||
|
||||
Window = new MainWindow {DataContext = mainVM};
|
||||
NotifyIconManager notifyIconManager = new NotifyIconManager(API);
|
||||
PluginManager.Init(API);
|
||||
CommandArgsFactory.Execute(e.Args.ToList());
|
||||
|
||||
// happlebao todo: the whole setting releated initialization should be put into seperate class/method
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<system:String x:Key="actionKeywords">Action keywords</system:String>
|
||||
<system:String x:Key="pluginDirectory">Plugin Directory</system:String>
|
||||
<system:String x:Key="author">Author</system:String>
|
||||
<system:String x:Key="plugin_init_time">Init time: {0}ms</system:String>
|
||||
<system:String x:Key="plugin_init_time">Initialize time: {0}ms</system:String>
|
||||
<system:String x:Key="plugin_query_time">Query time: {0}ms</system:String>
|
||||
|
||||
<!--Setting Theme-->
|
||||
|
||||
@@ -19,36 +19,21 @@ namespace Wox
|
||||
{
|
||||
public class PublicAPIInstance : IPublicAPI
|
||||
{
|
||||
|
||||
private UserSettingStorage _settings;
|
||||
#region Constructor
|
||||
|
||||
public PublicAPIInstance(MainViewModel mainVM)
|
||||
{
|
||||
MainVM = mainVM;
|
||||
|
||||
|
||||
GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
|
||||
WebRequest.RegisterPrefix("data", new DataWebRequestFactory());
|
||||
|
||||
MainVM.ListeningKeyPressed += (o, e) =>
|
||||
{
|
||||
|
||||
if (e.KeyEventArgs.Key == Key.Back)
|
||||
{
|
||||
BackKeyDownEvent?.Invoke(new WoxKeyDownEventArgs
|
||||
{
|
||||
Query = MainVM.QueryText,
|
||||
keyEventArgs = e.KeyEventArgs
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
private MainViewModel MainVM
|
||||
public MainViewModel MainVM
|
||||
{
|
||||
get;
|
||||
set;
|
||||
@@ -131,7 +116,11 @@ namespace Wox
|
||||
|
||||
public void ReloadPlugins()
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() => PluginManager.Init(this));
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
PluginManager.Initialize();
|
||||
PluginManager.InitializePlugins(this);
|
||||
});
|
||||
}
|
||||
|
||||
public string GetTranslation(string key)
|
||||
@@ -144,9 +133,9 @@ namespace Wox
|
||||
return PluginManager.AllPlugins.ToList();
|
||||
}
|
||||
|
||||
public event WoxKeyDownEventHandler BackKeyDownEvent;
|
||||
public event WoxGlobalKeyboardEventHandler GlobalKeyboardEvent;
|
||||
|
||||
[Obsolete("This will be removed in Wox 1.3")]
|
||||
public void PushResults(Query query, PluginMetadata plugin, List<Result> results)
|
||||
{
|
||||
results.ForEach(o =>
|
||||
|
||||
@@ -126,7 +126,7 @@
|
||||
<TextBlock Margin="5 0 0 0" ToolTip="Change Action Keywords" Cursor="Hand"
|
||||
MouseUp="PluginActionKeywords_OnMouseUp" Foreground="Blue" Text="keys"
|
||||
x:Name="pluginActionKeywords" />
|
||||
<TextBlock Margin="10 0 0 0" Text="Init time: 0ms" x:Name="pluginInitTime" />
|
||||
<TextBlock Margin="10 0 0 0" Text="Initialize time: 0ms" x:Name="pluginInitTime" />
|
||||
<TextBlock Margin="10 0 0 0" Text="Query time: 0ms" x:Name="pluginQueryTime" />
|
||||
<TextBlock HorizontalAlignment="Right" Cursor="Hand"
|
||||
MouseUp="tbOpenPluginDirecoty_MouseUp" Foreground="Blue"
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Helper;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Hotkey;
|
||||
@@ -34,19 +36,28 @@ namespace Wox.ViewModel
|
||||
private string _queryTextBeforeLoadContextMenu;
|
||||
private string _queryText;
|
||||
|
||||
private UserSettingStorage _settings;
|
||||
private QueryHistoryStorage _queryHistory;
|
||||
private UserSelectedRecordStorage _userSelectedRecord;
|
||||
private TopMostRecordStorage _topMostRecord;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
public MainViewModel()
|
||||
public MainViewModel(UserSettingStorage settings)
|
||||
{
|
||||
_queryTextBeforeLoadContextMenu = "";
|
||||
_queryText = "";
|
||||
_lastQuery = new Query();
|
||||
_settings = settings;
|
||||
|
||||
InitializeResultListBox();
|
||||
InitializeContextMenu();
|
||||
InitializeKeyCommands();
|
||||
_queryHistory = QueryHistoryStorage.Instance;
|
||||
_userSelectedRecord = UserSelectedRecordStorage.Instance;
|
||||
_topMostRecord = TopMostRecordStorage.Instance;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -243,13 +254,13 @@ namespace Wox.ViewModel
|
||||
|
||||
DisplayNextQueryCommand = new RelayCommand(_ =>
|
||||
{
|
||||
var nextQuery = QueryHistoryStorage.Instance.Next();
|
||||
var nextQuery = _queryHistory.Next();
|
||||
DisplayQueryHistory(nextQuery);
|
||||
});
|
||||
|
||||
DisplayPrevQueryCommand = new RelayCommand(_ =>
|
||||
{
|
||||
var prev = QueryHistoryStorage.Instance.Previous();
|
||||
var prev = _queryHistory.Previous();
|
||||
DisplayQueryHistory(prev);
|
||||
});
|
||||
|
||||
@@ -288,8 +299,8 @@ namespace Wox.ViewModel
|
||||
MainWindowVisibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
UserSelectedRecordStorage.Instance.Add(result);
|
||||
QueryHistoryStorage.Instance.Add(result.OriginQuery.RawQuery);
|
||||
_userSelectedRecord.Add(result);
|
||||
_queryHistory.Add(result.OriginQuery.RawQuery);
|
||||
});
|
||||
|
||||
LoadContextMenuCommand = new RelayCommand(_ =>
|
||||
@@ -413,7 +424,19 @@ namespace Wox.ViewModel
|
||||
}
|
||||
};
|
||||
action.Invoke();
|
||||
PluginManager.QueryForAllPlugins(query);
|
||||
var plugins = PluginManager.ValidPluginsForQuery(query);
|
||||
foreach (var plugin in plugins)
|
||||
{
|
||||
var config = _settings.CustomizedPluginConfigs[plugin.Metadata.ID];
|
||||
if (!config.Disabled)
|
||||
{
|
||||
ThreadPool.QueueUserWorkItem(o =>
|
||||
{
|
||||
var results = PluginManager.QueryForPlugin(plugin, query);
|
||||
UpdateResultView(results, plugin.Metadata, query);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IsProgressBarTooltipVisible = false;
|
||||
@@ -422,7 +445,7 @@ namespace Wox.ViewModel
|
||||
private void ResetQueryHistoryIndex()
|
||||
{
|
||||
Results.RemoveResultsFor(QueryHistoryStorage.MetaData);
|
||||
QueryHistoryStorage.Instance.Reset();
|
||||
_queryHistory.Reset();
|
||||
}
|
||||
|
||||
private void UpdateResultViewInternal(List<Result> list, PluginMetadata metadata)
|
||||
@@ -462,14 +485,14 @@ namespace Wox.ViewModel
|
||||
}
|
||||
private Result GetTopMostContextMenu(Result result)
|
||||
{
|
||||
if (TopMostRecordStorage.Instance.IsTopMost(result))
|
||||
if (_topMostRecord.IsTopMost(result))
|
||||
{
|
||||
return new Result(InternationalizationManager.Instance.GetTranslation("cancelTopMostInThisQuery"), "Images\\down.png")
|
||||
{
|
||||
PluginDirectory = WoxDirectroy.Executable,
|
||||
Action = _ =>
|
||||
{
|
||||
TopMostRecordStorage.Instance.Remove(result);
|
||||
_topMostRecord.Remove(result);
|
||||
App.API.ShowMsg("Succeed");
|
||||
return false;
|
||||
}
|
||||
@@ -482,7 +505,7 @@ namespace Wox.ViewModel
|
||||
PluginDirectory = WoxDirectroy.Executable,
|
||||
Action = _ =>
|
||||
{
|
||||
TopMostRecordStorage.Instance.AddOrUpdate(result);
|
||||
_topMostRecord.AddOrUpdate(result);
|
||||
App.API.ShowMsg("Succeed");
|
||||
return false;
|
||||
}
|
||||
@@ -500,7 +523,7 @@ namespace Wox.ViewModel
|
||||
|
||||
list.ForEach(o =>
|
||||
{
|
||||
o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o) * 5;
|
||||
o.Score += _userSelectedRecord.GetSelectedCount(o) * 5;
|
||||
});
|
||||
if (originQuery.RawQuery == _lastQuery.RawQuery)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user