diff --git a/Flow.Launcher/Storage/LastOpenedHistoryItem.cs b/Flow.Launcher/Storage/LastOpenedHistoryItem.cs index 47647066c91..c7f9144a781 100644 --- a/Flow.Launcher/Storage/LastOpenedHistoryItem.cs +++ b/Flow.Launcher/Storage/LastOpenedHistoryItem.cs @@ -10,6 +10,8 @@ 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 string IcoPath { get; set; } = string.Empty; + public GlyphInfo Glyph { get; init; } = null; public DateTime ExecutedDateTime { get; set; } public bool Equals(Result r) diff --git a/Flow.Launcher/Storage/QueryHistory.cs b/Flow.Launcher/Storage/QueryHistory.cs index 8284f7eea01..fde74bf17c5 100644 --- a/Flow.Launcher/Storage/QueryHistory.cs +++ b/Flow.Launcher/Storage/QueryHistory.cs @@ -44,11 +44,11 @@ public void Add(Result result) LastOpenedHistoryItems.RemoveAt(0); } - // If the last item is the same as the current result, just update the timestamp - if (LastOpenedHistoryItems.Count > 0 && - LastOpenedHistoryItems.Last().Equals(result)) + if (LastOpenedHistoryItems.Count > 0 && + TryGetLastOpenedHistoryResult(result, out var existingHistoryItem)) { - LastOpenedHistoryItems.Last().ExecutedDateTime = DateTime.Now; + existingHistoryItem.IcoPath = result.IcoPath; + existingHistoryItem.ExecutedDateTime = DateTime.Now; } else { @@ -59,9 +59,17 @@ public void Add(Result result) PluginID = result.PluginID, Query = result.OriginQuery.RawQuery, RecordKey = result.RecordKey, + IcoPath = result.IcoPath, + Glyph = result.Glyph, ExecutedDateTime = DateTime.Now }); } } + + private bool TryGetLastOpenedHistoryResult(Result result, out LastOpenedHistoryItem historyItem) + { + historyItem = LastOpenedHistoryItems.FirstOrDefault(x => x.Equals(result)); + return historyItem is not null; + } } } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index f0f4b257ac4..08d4e0d03e2 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1318,42 +1318,56 @@ private void QueryHistory() private List GetHistoryItems(IEnumerable historyItems) { var results = new List(); - if (Settings.HistoryStyle == HistoryStyle.Query) + + if (Settings.HistoryStyle == HistoryStyle.LastOpened) + { + historyItems = historyItems + .GroupBy(r => new { r.Title, r.SubTitle, r.PluginID, r.RecordKey }) + .Select(g => g.First()); + } + + foreach (var item in historyItems) { - foreach (var h in historyItems) + Result result = null; + var glyph = item.Glyph is null && !string.IsNullOrEmpty(item.IcoPath) // Some plugins won't have Glyph, then prefer IcoPath + ? null + : item.Glyph is not null + ? item.Glyph + : new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\uE81C"); // Default fallback + + var icoPath = !string.IsNullOrEmpty(item.IcoPath) ? item.IcoPath : Constant.HistoryIcon; + + if (Settings.HistoryStyle == HistoryStyle.Query) { - var result = new Result + result = new Result { - Title = Localize.executeQuery(h.Query), - SubTitle = Localize.lastExecuteTime(h.ExecutedDateTime), - IcoPath = Constant.HistoryIcon, - OriginQuery = new Query { RawQuery = h.Query }, + Title = Localize.executeQuery(item.Query), + SubTitle = Localize.lastExecuteTime(item.ExecutedDateTime), + IcoPath = icoPath, + OriginQuery = new Query { RawQuery = item.Query }, Action = _ => { App.API.BackToQueryResults(); - App.API.ChangeQuery(h.Query); + App.API.ChangeQuery(item.Query); return false; }, - Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\uE81C") + Glyph = glyph }; - results.Add(result); } - } - else - { - foreach (var h in historyItems) + else { - var result = new Result + + result = new Result { - Title = string.IsNullOrEmpty(h.Title) ? // Old migrated history items have no title - Localize.executeQuery(h.Query) : - h.Title, - SubTitle = Localize.lastExecuteTime(h.ExecutedDateTime), - IcoPath = Constant.HistoryIcon, - OriginQuery = new Query { RawQuery = h.Query }, + Title = string.IsNullOrEmpty(item.Title) ? // Old migrated history items have no title + Localize.executeQuery(item.Query) : + item.Title, + SubTitle = Localize.lastExecuteTime(item.ExecutedDateTime), + IcoPath = icoPath, + OriginQuery = new Query { RawQuery = item.Query }, AsyncAction = async c => { - var reflectResult = await ResultHelper.PopulateResultsAsync(h); + var reflectResult = await ResultHelper.PopulateResultsAsync(item); if (reflectResult != null) { // Record the user selected record for result ranking @@ -1366,14 +1380,16 @@ private List GetHistoryItems(IEnumerable historyI // If we cannot get the result, fallback to re-query App.API.BackToQueryResults(); - App.API.ChangeQuery(h.Query); + App.API.ChangeQuery(item.Query); return false; }, - Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\uE81C") + Glyph = glyph }; - results.Add(result); } + + results.Add(result); } + return results; }