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 BinaryStorage<Win32[]> _win32Storage;
private static BinaryStorage<UWP.Application[]> _uwpStorage;
private static BinaryStorage<UWP.Application[]> _uwpStorage;
private readonly PluginJsonStorage<Settings> _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<Result> 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;
},

View File

@ -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 =>
{

View File

@ -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;