/
githubmirror
/
PowerToys
Обзор
Документация
Войти
/
githubmirror
/
PowerToys
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/modules/launcher/PowerLauncher/Storage/QueryHistory.cs
63 строки
2 KB
gokcekantarci
[PTRun]Don't clear config data on upgrade (#30187)
06 фев 2024, 18:33
Не верифицирован
06 фев 2024, 18:33
1c7c100
Код
Авторство
О чём код?
// 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; using System.Collections.Generic; using System.Linq; using System.Text.Json.Serialization; namespace PowerLauncher.Storage { public class QueryHistory { [JsonInclude] public List<HistoryItem> Items { get; private set; } = new List<HistoryItem>(); private readonly int _maxHistory = 300; public void Add(string query) { if (string.IsNullOrEmpty(query)) { return; } if (Items.Count > _maxHistory) { Items.RemoveAt(0); } if (Items.Count > 0 && Items.Last().Query == query) { Items.Last().ExecutedDateTime = DateTime.Now; } else { Items.Add(new HistoryItem { Query = query, ExecutedDateTime = DateTime.Now, }); } } public void Update() { for (int i = Items.Count - 1; i >= 0; i--) { if (string.IsNullOrEmpty(Items[i].Query)) { Items.RemoveAt(i); } else { if (Items[i].ExecutedDateTime == DateTime.MinValue) { Items[i].ExecutedDateTime = DateTime.Now; } } } } } }