From c051c5cd50b8c997f59818f5b809040b980ea2c4 Mon Sep 17 00:00:00 2001 From: 01Dri Date: Wed, 8 Oct 2025 21:15:10 -0300 Subject: [PATCH] feat: new history logic in MainViewModel --- .../UserSettings/Settings.cs | 22 +++++++++++ Flow.Launcher/ViewModel/MainViewModel.cs | 37 +++---------------- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index e33bf04ac..0c839c497 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -215,6 +215,28 @@ namespace Flow.Launcher.Infrastructure.UserSettings } } } + private bool _showHistoryOnHomePage = true; + public bool ShowHistoryOnHomePage + { + get + { + if (ShowHistoryQueryResultsForHomePage || ShowHistoryLastOpenedResultsForHomePage) return true; + return _showHistoryOnHomePage; + } + set + { + if (_showHistoryOnHomePage != value) + { + _showHistoryOnHomePage = value; + OnPropertyChanged(); + if (value == false) + { + ShowHistoryQueryResultsForHomePage = false; + ShowHistoryLastOpenedResultsForHomePage = false; + } + } + } + } private bool _showHistoryQueryResultsForHomePage = false; public bool ShowHistoryQueryResultsForHomePage diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index d4dda62aa..23dac59e9 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -536,7 +536,10 @@ namespace Flow.Launcher.ViewModel if (QueryResultsSelected()) { - _history.AddToHistory(result, Settings); + if (Settings.ShowHistoryOnHomePage) + { + _history.AddToHistory(result, Settings); + } _userSelectedRecord.Add(result); lastHistoryIndex = 1; } @@ -1320,38 +1323,8 @@ namespace Flow.Launcher.ViewModel private List GetHistoryResults(IEnumerable historyItems) { var results = new List(); - Func defaultAction = _ => false; - foreach (var h in historyItems) { - // Achar uma forma melhor de fazer isso - if (Settings.ShowHistoryLastOpenedResultsForHomePage) - { - var pluginPair = PluginManager.GetPluginForId(h.PluginID); - if (pluginPair != null) - { - var queryResults = PluginManager - .QueryForPluginAsync(pluginPair, h.OriginQuery, CancellationToken.None) - .GetAwaiter() - .GetResult(); - var originalResult = queryResults?.FirstOrDefault(r => - r.Title == h.Title && r.SubTitle == h.SubTitle); - if (originalResult?.Action != null) - { - defaultAction = originalResult.Action; - } - - } - } - else - { - defaultAction = _ => - { - App.API.BackToQueryResults(); - App.API.ChangeQuery(h.OriginQuery.RawQuery); - return false; - }; - } var timeT = App.API.GetTranslation("lastExecuteTime"); var result = new Result { @@ -1360,7 +1333,7 @@ namespace Flow.Launcher.ViewModel IcoPath = Constant.HistoryIcon, PluginID = h.PluginID, OriginQuery = h.OriginQuery, - Action = defaultAction, + Action = Settings.ShowHistoryLastOpenedResultsForHomePage ? h.ExecuteAction : h.QueryAction, Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\uE81C") }; results.Add(result);