From 132d0631d2c0e68e62327ace0d4517de48901150 Mon Sep 17 00:00:00 2001 From: AT <14300910+theClueless@users.noreply.github.com> Date: Fri, 29 Nov 2019 01:38:50 +0200 Subject: [PATCH] program lock bug --- Plugins/Wox.Plugin.Program/Main.cs | 42 +++++++++++--------- Plugins/Wox.Plugin.Program/Programs/UWP.cs | 8 +++- Plugins/Wox.Plugin.Program/Programs/Win32.cs | 10 ++++- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/Plugins/Wox.Plugin.Program/Main.cs b/Plugins/Wox.Plugin.Program/Main.cs index e165a10826..a37e9f2028 100644 --- a/Plugins/Wox.Plugin.Program/Main.cs +++ b/Plugins/Wox.Plugin.Program/Main.cs @@ -24,7 +24,7 @@ namespace Wox.Plugin.Program private static PluginInitContext _context; private static BinaryStorage _win32Storage; - private static BinaryStorage _uwpStorage; + private static BinaryStorage _uwpStorage; private readonly PluginJsonStorage _settingsStorage; public Main() @@ -41,7 +41,7 @@ namespace Wox.Plugin.Program }); Log.Info($"|Wox.Plugin.Program.Main|Number of preload win32 programs <{_win32s.Length}>"); Log.Info($"|Wox.Plugin.Program.Main|Number of preload uwps <{_uwps.Length}>"); - + var a = Task.Run(() => { if (IsStartupIndexProgramsRequired || !_win32s.Any()) @@ -68,19 +68,25 @@ namespace Wox.Plugin.Program public List Query(Query query) { + Win32[] win32; + UWP.Application[] uwps; + lock (IndexLock) - { - var results1 = _win32s.AsParallel() - .Where(p => p.Enabled) - .Select(p => p.Result(query.Search, _context.API)); - - var results2 = _uwps.AsParallel() - .Where(p => p.Enabled) - .Select(p => p.Result(query.Search, _context.API)); - - var result = results1.Concat(results2).Where(r => r.Score > 0).ToList(); - return result; + { // just take the reference inside the lock to eliminate query time issues. + win32 = _win32s; + uwps = _uwps; } + + var results1 = win32.AsParallel() + .Where(p => p.Enabled) + .Select(p => p.Result(query.Search, _context.API)); + + var results2 = uwps.AsParallel() + .Where(p => p.Enabled) + .Select(p => p.Result(query.Search, _context.API)); + + var result = results1.Concat(results2).Where(r => r != null && r.Score > 0).ToList(); + return result; } public void Init(PluginInitContext context) @@ -111,14 +117,14 @@ namespace Wox.Plugin.Program public static void IndexPrograms() { - var t1 = Task.Run(()=>IndexWin32Programs()); + var t1 = Task.Run(() => IndexWin32Programs()); - var t2 = Task.Run(()=>IndexUWPPrograms()); + var t2 = Task.Run(() => IndexUWPPrograms()); Task.WaitAll(t1, t2); _settings.LastIndexTime = DateTime.Today; - } + } public Control CreateSettingPanel() { @@ -141,7 +147,7 @@ namespace Wox.Plugin.Program var program = selectedResult.ContextData as IProgram; if (program != null) { - menuOptions = program.ContextMenus(_context.API); + menuOptions = program.ContextMenus(_context.API); } menuOptions.Add( @@ -151,7 +157,7 @@ namespace Wox.Plugin.Program Action = c => { DisableProgram(program); - _context.API.ShowMsg(_context.API.GetTranslation("wox_plugin_program_disable_dlgtitle_success"), + _context.API.ShowMsg(_context.API.GetTranslation("wox_plugin_program_disable_dlgtitle_success"), _context.API.GetTranslation("wox_plugin_program_disable_dlgtitle_success_message")); return false; }, diff --git a/Plugins/Wox.Plugin.Program/Programs/UWP.cs b/Plugins/Wox.Plugin.Program/Programs/UWP.cs index 77d33e2e2f..2c608807b4 100644 --- a/Plugins/Wox.Plugin.Program/Programs/UWP.cs +++ b/Plugins/Wox.Plugin.Program/Programs/UWP.cs @@ -276,11 +276,17 @@ namespace Wox.Plugin.Program.Programs public Result Result(string query, IPublicAPI api) { + var score = Score(query); + if (score <= 0) + { // no need to create result if score is 0 + return null; + } + var result = new Result { SubTitle = Package.Location, Icon = Logo, - Score = Score(query), + Score = score, ContextData = this, Action = e => { diff --git a/Plugins/Wox.Plugin.Program/Programs/Win32.cs b/Plugins/Wox.Plugin.Program/Programs/Win32.cs index dc11a56654..36e08a3c46 100644 --- a/Plugins/Wox.Plugin.Program/Programs/Win32.cs +++ b/Plugins/Wox.Plugin.Program/Programs/Win32.cs @@ -45,11 +45,17 @@ namespace Wox.Plugin.Program.Programs public Result Result(string query, IPublicAPI api) { + var score = Score(query); + if (score <= 0) + { // no need to create result if this is zero + return null; + } + var result = new Result { SubTitle = FullPath, IcoPath = IcoPath, - Score = Score(query), + Score = score, ContextData = this, Action = e => { @@ -193,7 +199,7 @@ namespace Wox.Plugin.Program.Programs catch (COMException e) { // C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\MiracastView.lnk always cause exception - ProgramLogger.LogException($"|Win32|LnkProgram|{path}"+ + ProgramLogger.LogException($"|Win32|LnkProgram|{path}" + "|Error caused likely due to trying to get the description of the program", e); program.Valid = false;