mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
commit
982cac3472
6 changed files with 41 additions and 35 deletions
|
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace Wox.Infrastructure.Storage
|
||||
{
|
||||
class WoxJsonStorage<T> : JsonStrorage<T> where T : new()
|
||||
public class WoxJsonStorage<T> : JsonStrorage<T> where T : new()
|
||||
{
|
||||
public WoxJsonStorage()
|
||||
{
|
||||
|
|
@ -18,4 +18,4 @@ namespace Wox.Infrastructure.Storage
|
|||
FilePath = Path.Combine(directoryPath, $"{filename}{FileSuffix}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -108,7 +108,7 @@ namespace Wox.Plugin
|
|||
public object ContextData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Plugin ID that generate this result
|
||||
/// Plugin ID that generated this result
|
||||
/// </summary>
|
||||
public string PluginID { get; internal set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,47 +1,50 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Storage
|
||||
{
|
||||
// todo this class is not thread safe.... but used from multiple threads.
|
||||
public class TopMostRecord
|
||||
{
|
||||
public Dictionary<string, Record> records = new Dictionary<string, Record>();
|
||||
[JsonProperty]
|
||||
private Dictionary<string, Record> records = new Dictionary<string, Record>();
|
||||
|
||||
internal bool IsTopMost(Result result)
|
||||
{
|
||||
if (records.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// since this dictionary should be very small (or empty) going over it should be pretty fast.
|
||||
return records.Any(o => o.Value.Title == result.Title
|
||||
&& o.Value.SubTitle == result.SubTitle
|
||||
&& o.Value.PluginID == result.PluginID
|
||||
&& o.Key == result.OriginQuery.RawQuery);
|
||||
&& o.Value.SubTitle == result.SubTitle
|
||||
&& o.Value.PluginID == result.PluginID
|
||||
&& o.Key == result.OriginQuery.RawQuery);
|
||||
}
|
||||
|
||||
internal void Remove(Result result)
|
||||
{
|
||||
if (records.ContainsKey(result.OriginQuery.RawQuery))
|
||||
{
|
||||
records.Remove(result.OriginQuery.RawQuery);
|
||||
}
|
||||
records.Remove(result.OriginQuery.RawQuery);
|
||||
}
|
||||
|
||||
internal void AddOrUpdate(Result result)
|
||||
{
|
||||
if (records.ContainsKey(result.OriginQuery.RawQuery))
|
||||
var record = new Record
|
||||
{
|
||||
records[result.OriginQuery.RawQuery].Title = result.Title;
|
||||
records[result.OriginQuery.RawQuery].SubTitle = result.SubTitle;
|
||||
records[result.OriginQuery.RawQuery].PluginID = result.PluginID;
|
||||
}
|
||||
else
|
||||
{
|
||||
records.Add(result.OriginQuery.RawQuery, new Record
|
||||
{
|
||||
PluginID = result.PluginID,
|
||||
Title = result.Title,
|
||||
SubTitle = result.SubTitle
|
||||
});
|
||||
}
|
||||
PluginID = result.PluginID,
|
||||
Title = result.Title,
|
||||
SubTitle = result.SubTitle
|
||||
};
|
||||
records[result.OriginQuery.RawQuery] = record;
|
||||
|
||||
}
|
||||
|
||||
public void Load(Dictionary<string, Record> dictionary)
|
||||
{
|
||||
records = dictionary;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,21 +12,23 @@ namespace Wox.Storage
|
|||
|
||||
public void Add(Result result)
|
||||
{
|
||||
if (records.ContainsKey(result.ToString()))
|
||||
var key = result.ToString();
|
||||
if (records.TryGetValue(key, out int value))
|
||||
{
|
||||
records[result.ToString()] += 1;
|
||||
records[key] = value + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
records.Add(result.ToString(), 1);
|
||||
records.Add(key, 1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public int GetSelectedCount(Result result)
|
||||
{
|
||||
if (records.ContainsKey(result.ToString()))
|
||||
if (records.TryGetValue(result.ToString(), out int value))
|
||||
{
|
||||
return records[result.ToString()];
|
||||
return value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -419,6 +419,11 @@ namespace Wox.ViewModel
|
|||
UpdateResultView(results, plugin.Metadata, query);
|
||||
}
|
||||
});
|
||||
|
||||
// this should happen once after all queries are done so progress bar should continue
|
||||
// until the end of all querying
|
||||
_queryHasReturn = true;
|
||||
ProgressBarVisibility = Visibility.Hidden;
|
||||
}, _updateToken);
|
||||
}
|
||||
}
|
||||
|
|
@ -627,9 +632,6 @@ namespace Wox.ViewModel
|
|||
/// </summary>
|
||||
public void UpdateResultView(List<Result> list, PluginMetadata metadata, Query originQuery)
|
||||
{
|
||||
_queryHasReturn = true;
|
||||
ProgressBarVisibility = Visibility.Hidden;
|
||||
|
||||
foreach (var result in list)
|
||||
{
|
||||
if (_topMostRecord.IsTopMost(result))
|
||||
|
|
|
|||
|
|
@ -155,7 +155,6 @@ namespace Wox.ViewModel
|
|||
// Find the same results in A (old results) and B (new newResults)
|
||||
var sameResults = oldResults
|
||||
.Where(t1 => newResults.Any(x => x.Result.Equals(t1.Result)))
|
||||
.Select(t1 => t1)
|
||||
.ToList();
|
||||
|
||||
// remove result of relative complement of B in A
|
||||
|
|
|
|||
Loading…
Reference in a new issue