diff --git a/Plugins/Wox.Plugin.Program/Main.cs b/Plugins/Wox.Plugin.Program/Main.cs index 87956af6c..0d855f421 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) @@ -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 diff --git a/Wox/Converters/HighlightTextConverter.cs b/Wox/Converters/HighlightTextConverter.cs index 2213eb9b3..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; - var resources = ThemeManager.Instance.GetResourceDictionary(); - - 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 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(() => {