From 8c448d58f47e34f2cb3f257c45114c09516e00cb Mon Sep 17 00:00:00 2001 From: bao-qian Date: Thu, 30 Apr 2020 20:33:14 +0800 Subject: [PATCH 1/5] use already load resource --- Wox/Converters/HighlightTextConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Wox/Converters/HighlightTextConverter.cs b/Wox/Converters/HighlightTextConverter.cs index 2213eb9b3..644e814ba 100644 --- a/Wox/Converters/HighlightTextConverter.cs +++ b/Wox/Converters/HighlightTextConverter.cs @@ -29,7 +29,7 @@ public object Convert(object[] value, Type targetType, object parameter, Culture } var settings = (Application.Current as App).Settings; - var resources = ThemeManager.Instance.GetResourceDictionary(); + ResourceDictionary resources = Application.Current.Resources; var highlightColor = (Brush) (selected? resources.Contains("ItemSelectedHighlightColor")? resources["ItemSelectedHighlightColor"]: resources["BaseItemSelectedHighlightColor"]: From 55a1128213ef3f8262af94b1229f42e2ec7a8c79 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Thu, 30 Apr 2020 21:35:24 +0800 Subject: [PATCH 2/5] load resource only once --- Wox/Converters/HighlightTextConverter.cs | 56 +++++++++++++++++------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/Wox/Converters/HighlightTextConverter.cs b/Wox/Converters/HighlightTextConverter.cs index 644e814ba..bff2a98d6 100644 --- a/Wox/Converters/HighlightTextConverter.cs +++ b/Wox/Converters/HighlightTextConverter.cs @@ -9,18 +9,43 @@ using System.Windows.Documents; using System.Windows.Media; using Wox.Core.Resource; +using Wox.Infrastructure.UserSettings; namespace Wox.Converters { + internal class HightLightStyle + { + public Brush Color { get; set; } + public FontStyle FontStyle { get; set; } + public FontWeight FontWeight { get; set; } + public FontStretch FontStretch { get; set; } + + internal HightLightStyle(bool selected) + { + var app = Application.Current as App; + Settings settings = app.Settings; + ResourceDictionary resources = app.Resources; + + Color = (Brush)(selected ? + resources.Contains("ItemSelectedHighlightColor") ? resources["ItemSelectedHighlightColor"] : resources["BaseItemSelectedHighlightColor"] : + resources.Contains("ItemHighlightColor") ? resources["ItemHighlightColor"] : resources["BaseItemHighlightColor"]); + FontStyle = FontHelper.GetFontStyleFromInvariantStringOrNormal(settings.ResultHighlightFontStyle); + FontWeight = FontHelper.GetFontWeightFromInvariantStringOrNormal(settings.ResultHighlightFontWeight); + FontStretch = FontHelper.GetFontStretchFromInvariantStringOrNormal(settings.ResultHighlightFontStretch); + } + + } public class HighlightTextConverter : IMultiValueConverter { + private static Lazy _highLightStyle = new Lazy(() => new HightLightStyle(false)); + private static Lazy _highLightSelectedStyle = new Lazy(() => new HightLightStyle(true)); + public object Convert(object[] value, Type targetType, object parameter, CultureInfo cultureInfo) { var text = value[0] as string; var highlightData = value[1] as List; var selected = value[2] as bool? == true; - var textBlock = new Span(); if (highlightData == null || !highlightData.Any()) { @@ -28,16 +53,17 @@ public object Convert(object[] value, Type targetType, object parameter, Culture return new Run(text); } - var settings = (Application.Current as App).Settings; - ResourceDictionary resources = Application.Current.Resources; - - var highlightColor = (Brush) (selected? - resources.Contains("ItemSelectedHighlightColor")? resources["ItemSelectedHighlightColor"]: resources["BaseItemSelectedHighlightColor"]: - resources.Contains("ItemHighlightColor")? resources["ItemHighlightColor"]: resources["BaseItemHighlightColor"]); - var highlightStyle = FontHelper.GetFontStyleFromInvariantStringOrNormal(settings.ResultHighlightFontStyle); - var highlightWeight = FontHelper.GetFontWeightFromInvariantStringOrNormal(settings.ResultHighlightFontWeight); - var highlightStretch = FontHelper.GetFontStretchFromInvariantStringOrNormal(settings.ResultHighlightFontStretch); - + HightLightStyle style; + if (selected) + { + style = _highLightSelectedStyle.Value; + } + else + { + style = _highLightStyle.Value; + } + + var textBlock = new Span(); for (var i = 0; i < text.Length; i++) { var currentCharacter = text.Substring(i, 1); @@ -45,10 +71,10 @@ public object Convert(object[] value, Type targetType, object parameter, Culture { textBlock.Inlines.Add((new Run(currentCharacter) { - Foreground = highlightColor, - FontWeight = highlightWeight, - FontStyle = highlightStyle, - FontStretch = highlightStretch + Foreground = style.Color, + FontWeight = style.FontWeight, + FontStyle = style.FontStyle, + FontStretch = style.FontStretch })); } else From 225b51856feb19a4ce24f0de7d820e22e17a0a37 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Thu, 30 Apr 2020 22:36:38 +0800 Subject: [PATCH 3/5] remove lock which will speedup startup search speed --- Plugins/Wox.Plugin.Program/Main.cs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/Plugins/Wox.Plugin.Program/Main.cs b/Plugins/Wox.Plugin.Program/Main.cs index 87956af6c..9750025e4 100644 --- a/Plugins/Wox.Plugin.Program/Main.cs +++ b/Plugins/Wox.Plugin.Program/Main.cs @@ -42,7 +42,7 @@ private static void preloadPrograms() }); Logger.WoxInfo($"Number of preload win32 programs <{_win32s.Length}>"); Logger.WoxInfo($"Number of preload uwps <{_uwps.Length}>"); - } + } public void Save() { @@ -55,11 +55,8 @@ public List Query(Query query) { Win32[] win32; UWP.Application[] uwps; - lock (IndexLock) - { // just take the reference inside the lock to eliminate query time issues. - win32 = _win32s; - uwps = _uwps; - } + win32 = _win32s; + uwps = _uwps; var results1 = win32.AsParallel() .Where(p => p.Enabled) @@ -94,7 +91,7 @@ public void Init(PluginInitContext context) preloadPrograms(); - Task.Delay(2000).ContinueWith(_ => + Task.Delay(20000).ContinueWith(_ => { IndexPrograms(); }); @@ -109,10 +106,7 @@ public void loadSettings() public static void IndexWin32Programs() { var win32S = Win32.All(_settings); - lock (IndexLock) - { - _win32s = win32S; - } + _win32s = win32S; } public static void IndexUWPPrograms() @@ -122,10 +116,7 @@ public static void IndexUWPPrograms() var applications = support ? UWP.All() : new UWP.Application[] { }; //var applications = new UWP.Application[] { }; - lock (IndexLock) - { - _uwps = applications; - } + _uwps = applications; } public static void IndexPrograms() @@ -181,7 +172,7 @@ public List LoadContextMenus(Result selectedResult) return menuOptions; } - + public static void StartProcess(Func runProcess, ProcessStartInfo info) { try From c69892069b3ddc05ada039739327de5e38b096e1 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Thu, 30 Apr 2020 22:38:58 +0800 Subject: [PATCH 4/5] fixup delay --- Plugins/Wox.Plugin.Program/Main.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Wox.Plugin.Program/Main.cs b/Plugins/Wox.Plugin.Program/Main.cs index 9750025e4..0d855f421 100644 --- a/Plugins/Wox.Plugin.Program/Main.cs +++ b/Plugins/Wox.Plugin.Program/Main.cs @@ -91,7 +91,7 @@ public void Init(PluginInitContext context) preloadPrograms(); - Task.Delay(20000).ContinueWith(_ => + Task.Delay(2000).ContinueWith(_ => { IndexPrograms(); }); From be070265cdd291455f69f7d45880e9bca00d4db1 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Thu, 30 Apr 2020 22:39:09 +0800 Subject: [PATCH 5/5] query result async --- Wox/ViewModel/MainViewModel.cs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/Wox/ViewModel/MainViewModel.cs b/Wox/ViewModel/MainViewModel.cs index 7d4f28c35..8143fb8fd 100644 --- a/Wox/ViewModel/MainViewModel.cs +++ b/Wox/ViewModel/MainViewModel.cs @@ -472,23 +472,26 @@ private void QueryResults() }; CountdownEvent countdown = new CountdownEvent(plugins.Count); - Parallel.ForEach(plugins, plugin => + foreach (var plugin in plugins) { - if (token.IsCancellationRequested) + Task.Run(() => { - Logger.WoxTrace($"canceled {token.GetHashCode()} {Thread.CurrentThread.ManagedThreadId} {queryText} {plugin.Metadata.Name}"); - countdown.Signal(); - return; - } - var results = PluginManager.QueryForPlugin(plugin, query); - if (token.IsCancellationRequested) - { - Logger.WoxTrace($"canceled {token.GetHashCode()} {Thread.CurrentThread.ManagedThreadId} {queryText} {plugin.Metadata.Name}"); - countdown.Signal(); - return; - } - _resultsQueue.Add(new ResultsForUpdate(results, plugin.Metadata, query, token, countdown)); - }); + if (token.IsCancellationRequested) + { + Logger.WoxTrace($"canceled {token.GetHashCode()} {Thread.CurrentThread.ManagedThreadId} {queryText} {plugin.Metadata.Name}"); + countdown.Signal(); + return; + } + var results = PluginManager.QueryForPlugin(plugin, query); + if (token.IsCancellationRequested) + { + Logger.WoxTrace($"canceled {token.GetHashCode()} {Thread.CurrentThread.ManagedThreadId} {queryText} {plugin.Metadata.Name}"); + countdown.Signal(); + return; + } + _resultsQueue.Add(new ResultsForUpdate(results, plugin.Metadata, query, token, countdown)); + }, token); + } Task.Run(() => {