diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index da712e3fc..6adefdb6a 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -716,9 +716,9 @@ namespace Flow.Launcher.Infrastructure.UserSettings public enum HistoryStyle { [EnumLocalizeKey(nameof(Localize.queryHistory))] - Query = 1, + Query, [EnumLocalizeKey(nameof(Localize.executedHistory))] - LastOpened = 2 + LastOpened } } diff --git a/Flow.Launcher/Helper/ResultHelper.cs b/Flow.Launcher/Helper/ResultHelper.cs index f2ba66cbf..f99ba0377 100644 --- a/Flow.Launcher/Helper/ResultHelper.cs +++ b/Flow.Launcher/Helper/ResultHelper.cs @@ -2,7 +2,6 @@ using System.Threading; using System.Threading.Tasks; using Flow.Launcher.Core.Plugin; -using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; using Flow.Launcher.Storage; @@ -42,20 +41,4 @@ public static class ResultHelper return null; } } - - public static bool IsEquals(this Result result, LastOpenedHistoryItem item, HistoryStyle style) - { - bool keyMatches = string.IsNullOrEmpty(result.RecordKey) && string.IsNullOrEmpty(item.RecordKey) - ? item.Title == result.Title - : !string.IsNullOrEmpty(result.RecordKey) && !string.IsNullOrEmpty(item.RecordKey) && item.RecordKey == result.RecordKey; - - bool queryMatches = style != HistoryStyle.Query || (result.OriginQuery != null && item.Query == result.OriginQuery.RawQuery); - - - return keyMatches - && queryMatches - && item.SubTitle == result.SubTitle - && item.PluginID == result.PluginID - && item.HistoryStyle == style; - } } diff --git a/Flow.Launcher/Storage/LastOpenedHistoryItem.cs b/Flow.Launcher/Storage/LastOpenedHistoryItem.cs index 1cf93b1ff..47647066c 100644 --- a/Flow.Launcher/Storage/LastOpenedHistoryItem.cs +++ b/Flow.Launcher/Storage/LastOpenedHistoryItem.cs @@ -1,5 +1,4 @@ using System; -using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; namespace Flow.Launcher.Storage; @@ -11,7 +10,22 @@ public class LastOpenedHistoryItem public string PluginID { get; set; } = string.Empty; public string Query { get; set; } = string.Empty; public string RecordKey { get; set; } = string.Empty; - public HistoryStyle HistoryStyle { get; set; } public DateTime ExecutedDateTime { get; set; } + public bool Equals(Result r) + { + if (string.IsNullOrEmpty(RecordKey) || string.IsNullOrEmpty(r.RecordKey)) + { + return Title == r.Title + && SubTitle == r.SubTitle + && PluginID == r.PluginID + && Query == r.OriginQuery.RawQuery; + } + else + { + return RecordKey == r.RecordKey + && PluginID == r.PluginID + && Query == r.OriginQuery.RawQuery; + } + } } diff --git a/Flow.Launcher/Storage/QueryHistory.cs b/Flow.Launcher/Storage/QueryHistory.cs index 5d19aed38..7d264d09f 100644 --- a/Flow.Launcher/Storage/QueryHistory.cs +++ b/Flow.Launcher/Storage/QueryHistory.cs @@ -2,9 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Text.Json.Serialization; -using CommunityToolkit.Mvvm.DependencyInjection; -using Flow.Launcher.Helper; -using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; namespace Flow.Launcher.Storage @@ -19,11 +16,8 @@ namespace Flow.Launcher.Storage [JsonInclude] public List LastOpenedHistoryItems { get; private set; } = []; - private readonly Settings _settings = Ioc.Default.GetRequiredService(); - private readonly int _maxHistory = 300; - public void PopulateHistoryFromLegacyHistory() { if (Items.Count == 0) return; @@ -31,58 +25,42 @@ namespace Flow.Launcher.Storage foreach (var item in Items) { LastOpenedHistoryItems.Add(new LastOpenedHistoryItem - { + { Query = item.Query, - ExecutedDateTime = item.ExecutedDateTime, - HistoryStyle = HistoryStyle.Query + ExecutedDateTime = item.ExecutedDateTime }); } Items.Clear(); } public void Add(Result result) - { + { if (string.IsNullOrEmpty(result.OriginQuery.RawQuery)) return; - if (string.IsNullOrEmpty(result.PluginID)) return; - var style = _settings.HistoryStyle; // Maintain the max history limit - if (LastOpenedHistoryItems.Count > _maxHistory) + if (LastOpenedHistoryItems.Count > _maxHistory) { LastOpenedHistoryItems.RemoveAt(0); } // If the last item is the same as the current result, just update the timestamp - if (LastOpenedHistoryItems.Count > 0) + if (LastOpenedHistoryItems.Count > 0 && + LastOpenedHistoryItems.Last().Equals(result)) { - var last = LastOpenedHistoryItems.Last(); - if (result.IsEquals(last, style)) - { - last.ExecutedDateTime = DateTime.Now; - return; - } - - var existItem = LastOpenedHistoryItems.FirstOrDefault(x => result.IsEquals(x, style)); - - if (existItem != null) - { - existItem.ExecutedDateTime = DateTime.Now; - return; - } + LastOpenedHistoryItems.Last().ExecutedDateTime = DateTime.Now; } - - LastOpenedHistoryItems.Add(new LastOpenedHistoryItem + else { - Title = result.Title, - SubTitle = result.SubTitle, - PluginID = result.PluginID, - Query = result.OriginQuery.RawQuery, - RecordKey = result.RecordKey, - ExecutedDateTime = DateTime.Now, - HistoryStyle = style - }); + LastOpenedHistoryItems.Add(new LastOpenedHistoryItem + { + Title = result.Title, + SubTitle = result.SubTitle, + PluginID = result.PluginID, + Query = result.OriginQuery.RawQuery, + RecordKey = result.RecordKey, + ExecutedDateTime = DateTime.Now + }); + } } - - } } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 22476a79c..8fd6de6f5 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1318,10 +1318,9 @@ namespace Flow.Launcher.ViewModel private List GetHistoryItems(IEnumerable historyItems) { var results = new List(); - var historyItemsFiltered = historyItems.Where(x => x.HistoryStyle == Settings.HistoryStyle).ToList(); if (Settings.HistoryStyle == HistoryStyle.Query) { - foreach (var h in historyItemsFiltered) + foreach (var h in historyItems) { var result = new Result { @@ -1342,7 +1341,7 @@ namespace Flow.Launcher.ViewModel } else { - foreach (var h in historyItemsFiltered) + foreach (var h in historyItems) { var result = new Result { @@ -1365,14 +1364,15 @@ namespace Flow.Launcher.ViewModel { await reflectResult.AsyncAction(c); } - return false; } - - App.API.BackToQueryResults(); - App.API.ChangeQuery(h.Query); - return false; - }, + else + { + App.API.BackToQueryResults(); + App.API.ChangeQuery(h.Query); + return false; + } + }, Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\uE81C") }; results.Add(result);