program lock bug

This commit is contained in:
AT
2019-11-29 01:38:50 +02:00
parent 09c7955149
commit 132d0631d2
3 changed files with 39 additions and 21 deletions

View File

@@ -24,7 +24,7 @@ namespace Wox.Plugin.Program
private static PluginInitContext _context; private static PluginInitContext _context;
private static BinaryStorage<Win32[]> _win32Storage; private static BinaryStorage<Win32[]> _win32Storage;
private static BinaryStorage<UWP.Application[]> _uwpStorage; private static BinaryStorage<UWP.Application[]> _uwpStorage;
private readonly PluginJsonStorage<Settings> _settingsStorage; private readonly PluginJsonStorage<Settings> _settingsStorage;
public Main() 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 win32 programs <{_win32s.Length}>");
Log.Info($"|Wox.Plugin.Program.Main|Number of preload uwps <{_uwps.Length}>"); Log.Info($"|Wox.Plugin.Program.Main|Number of preload uwps <{_uwps.Length}>");
var a = Task.Run(() => var a = Task.Run(() =>
{ {
if (IsStartupIndexProgramsRequired || !_win32s.Any()) if (IsStartupIndexProgramsRequired || !_win32s.Any())
@@ -68,19 +68,25 @@ namespace Wox.Plugin.Program
public List<Result> Query(Query query) public List<Result> Query(Query query)
{ {
Win32[] win32;
UWP.Application[] uwps;
lock (IndexLock) lock (IndexLock)
{ { // just take the reference inside the lock to eliminate query time issues.
var results1 = _win32s.AsParallel() win32 = _win32s;
.Where(p => p.Enabled) uwps = _uwps;
.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;
} }
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) public void Init(PluginInitContext context)
@@ -111,14 +117,14 @@ namespace Wox.Plugin.Program
public static void IndexPrograms() 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); Task.WaitAll(t1, t2);
_settings.LastIndexTime = DateTime.Today; _settings.LastIndexTime = DateTime.Today;
} }
public Control CreateSettingPanel() public Control CreateSettingPanel()
{ {
@@ -141,7 +147,7 @@ namespace Wox.Plugin.Program
var program = selectedResult.ContextData as IProgram; var program = selectedResult.ContextData as IProgram;
if (program != null) if (program != null)
{ {
menuOptions = program.ContextMenus(_context.API); menuOptions = program.ContextMenus(_context.API);
} }
menuOptions.Add( menuOptions.Add(
@@ -151,7 +157,7 @@ namespace Wox.Plugin.Program
Action = c => Action = c =>
{ {
DisableProgram(program); 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")); _context.API.GetTranslation("wox_plugin_program_disable_dlgtitle_success_message"));
return false; return false;
}, },

View File

@@ -276,11 +276,17 @@ namespace Wox.Plugin.Program.Programs
public Result Result(string query, IPublicAPI api) 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 var result = new Result
{ {
SubTitle = Package.Location, SubTitle = Package.Location,
Icon = Logo, Icon = Logo,
Score = Score(query), Score = score,
ContextData = this, ContextData = this,
Action = e => Action = e =>
{ {

View File

@@ -45,11 +45,17 @@ namespace Wox.Plugin.Program.Programs
public Result Result(string query, IPublicAPI api) 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 var result = new Result
{ {
SubTitle = FullPath, SubTitle = FullPath,
IcoPath = IcoPath, IcoPath = IcoPath,
Score = Score(query), Score = score,
ContextData = this, ContextData = this,
Action = e => Action = e =>
{ {
@@ -193,7 +199,7 @@ namespace Wox.Plugin.Program.Programs
catch (COMException e) catch (COMException e)
{ {
// C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\MiracastView.lnk always cause exception // 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); "|Error caused likely due to trying to get the description of the program", e);
program.Valid = false; program.Valid = false;