mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Save QueryHistory, UserSelectedRecord after each update (#9165)
This commit is contained in:
@@ -1,53 +0,0 @@
|
|||||||
// Copyright (c) Microsoft Corporation
|
|
||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
||||||
// See the LICENSE file in the project root for more information.
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Wox.Plugin;
|
|
||||||
|
|
||||||
namespace PowerLauncher.Storage
|
|
||||||
{
|
|
||||||
// todo this class is not thread safe.... but used from multiple threads.
|
|
||||||
public class TopMostRecord
|
|
||||||
{
|
|
||||||
[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);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void Remove(Result result)
|
|
||||||
{
|
|
||||||
records.Remove(result.OriginQuery.RawQuery);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void AddOrUpdate(Result result)
|
|
||||||
{
|
|
||||||
var record = new Record
|
|
||||||
{
|
|
||||||
PluginID = result.PluginID,
|
|
||||||
Title = result.Title,
|
|
||||||
SubTitle = result.SubTitle,
|
|
||||||
};
|
|
||||||
records[result.OriginQuery.RawQuery] = record;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Load(Dictionary<string, Record> dictionary)
|
|
||||||
{
|
|
||||||
records = dictionary;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -37,11 +37,9 @@ namespace PowerLauncher.ViewModel
|
|||||||
|
|
||||||
private readonly WoxJsonStorage<QueryHistory> _historyItemsStorage;
|
private readonly WoxJsonStorage<QueryHistory> _historyItemsStorage;
|
||||||
private readonly WoxJsonStorage<UserSelectedRecord> _userSelectedRecordStorage;
|
private readonly WoxJsonStorage<UserSelectedRecord> _userSelectedRecordStorage;
|
||||||
private readonly WoxJsonStorage<TopMostRecord> _topMostRecordStorage;
|
|
||||||
private readonly PowerToysRunSettings _settings;
|
private readonly PowerToysRunSettings _settings;
|
||||||
private readonly QueryHistory _history;
|
private readonly QueryHistory _history;
|
||||||
private readonly UserSelectedRecord _userSelectedRecord;
|
private readonly UserSelectedRecord _userSelectedRecord;
|
||||||
private readonly TopMostRecord _topMostRecord;
|
|
||||||
private readonly object _addResultsLock = new object();
|
private readonly object _addResultsLock = new object();
|
||||||
private readonly System.Diagnostics.Stopwatch _hotkeyTimer = new System.Diagnostics.Stopwatch();
|
private readonly System.Diagnostics.Stopwatch _hotkeyTimer = new System.Diagnostics.Stopwatch();
|
||||||
|
|
||||||
@@ -66,10 +64,8 @@ namespace PowerLauncher.ViewModel
|
|||||||
|
|
||||||
_historyItemsStorage = new WoxJsonStorage<QueryHistory>();
|
_historyItemsStorage = new WoxJsonStorage<QueryHistory>();
|
||||||
_userSelectedRecordStorage = new WoxJsonStorage<UserSelectedRecord>();
|
_userSelectedRecordStorage = new WoxJsonStorage<UserSelectedRecord>();
|
||||||
_topMostRecordStorage = new WoxJsonStorage<TopMostRecord>();
|
|
||||||
_history = _historyItemsStorage.Load();
|
_history = _historyItemsStorage.Load();
|
||||||
_userSelectedRecord = _userSelectedRecordStorage.Load();
|
_userSelectedRecord = _userSelectedRecordStorage.Load();
|
||||||
_topMostRecord = _topMostRecordStorage.Load();
|
|
||||||
|
|
||||||
ContextMenu = new ResultsViewModel(_settings);
|
ContextMenu = new ResultsViewModel(_settings);
|
||||||
Results = new ResultsViewModel(_settings);
|
Results = new ResultsViewModel(_settings);
|
||||||
@@ -171,8 +167,11 @@ namespace PowerLauncher.ViewModel
|
|||||||
|
|
||||||
if (SelectedIsFromQueryResults())
|
if (SelectedIsFromQueryResults())
|
||||||
{
|
{
|
||||||
|
// todo: revert _userSelectedRecordStorage.Save() and _historyItemsStorage.Save() after https://github.com/microsoft/PowerToys/issues/9164 is done
|
||||||
_userSelectedRecord.Add(result);
|
_userSelectedRecord.Add(result);
|
||||||
|
_userSelectedRecordStorage.Save();
|
||||||
_history.Add(result.OriginQuery.RawQuery);
|
_history.Add(result.OriginQuery.RawQuery);
|
||||||
|
_historyItemsStorage.Save();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -793,7 +792,6 @@ namespace PowerLauncher.ViewModel
|
|||||||
{
|
{
|
||||||
_historyItemsStorage.Save();
|
_historyItemsStorage.Save();
|
||||||
_userSelectedRecordStorage.Save();
|
_userSelectedRecordStorage.Save();
|
||||||
_topMostRecordStorage.Save();
|
|
||||||
|
|
||||||
_saved = true;
|
_saved = true;
|
||||||
}
|
}
|
||||||
@@ -816,14 +814,7 @@ namespace PowerLauncher.ViewModel
|
|||||||
|
|
||||||
foreach (var result in list)
|
foreach (var result in list)
|
||||||
{
|
{
|
||||||
if (_topMostRecord.IsTopMost(result))
|
result.Score += _userSelectedRecord.GetSelectedCount(result) * 5;
|
||||||
{
|
|
||||||
result.Score = int.MaxValue;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result.Score += _userSelectedRecord.GetSelectedCount(result) * 5;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Using CurrentCultureIgnoreCase since this is user facing
|
// Using CurrentCultureIgnoreCase since this is user facing
|
||||||
|
|||||||
@@ -24,9 +24,10 @@ map<wstring, vector<wstring>> escapeInfo = {
|
|||||||
|
|
||||||
vector<wstring> filesToDelete = {
|
vector<wstring> filesToDelete = {
|
||||||
L"PowerToys Run\\Cache",
|
L"PowerToys Run\\Cache",
|
||||||
L"PowerToys Run\\Settings\\QueryHistory.json",
|
|
||||||
L"PowerRename\\replace-mru.json",
|
L"PowerRename\\replace-mru.json",
|
||||||
L"PowerRename\\search-mru.json"
|
L"PowerRename\\search-mru.json",
|
||||||
|
L"PowerToys Run\\Settings\\UserSelectedRecord.json",
|
||||||
|
L"PowerToys Run\\Settings\\QueryHistory.json"
|
||||||
};
|
};
|
||||||
|
|
||||||
vector<wstring> getXpathArray(wstring xpath)
|
vector<wstring> getXpathArray(wstring xpath)
|
||||||
|
|||||||
Reference in New Issue
Block a user