diff --git a/Flow.Launcher/Storage/History.cs b/Flow.Launcher/Storage/History.cs index 539ec64bb..542bfbebc 100644 --- a/Flow.Launcher/Storage/History.cs +++ b/Flow.Launcher/Storage/History.cs @@ -2,13 +2,11 @@ using System.Collections.Generic; using System.Linq; using System.Text.Json.Serialization; -using System.Threading; -using Flow.Launcher.Core.Plugin; +using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; namespace Flow.Launcher.Storage { - public class History { //Legacy @@ -30,11 +28,15 @@ namespace Flow.Launcher.Storage } - - public List GetHistoryItems(bool isQuery) + public List GetHistoryItems(Settings settings) { - if (isQuery) return PopulateActions(QueryHistoryItems, isQuery); - return PopulateActions(LastOpenedHistoryItems, isQuery); + if (settings.ShowHistoryOnHomePage) + { + if (settings.ShowHistoryQueryResultsForHomePage) return QueryHistoryItems.PopulateActions(true); + return LastOpenedHistoryItems.PopulateActions(false); + } + + return new List(); } public void PopulateHistoryWithLegacyHistory() @@ -45,46 +47,13 @@ namespace Flow.Launcher.Storage { RawQuery = item.Query, ExecutedDateTime = item.ExecutedDateTime ?? DateTime.Now, - QueryAction = GetQueryAction(item.Query) + QueryAction = HistoryHelper.GetQueryAction(item.Query) }); } if (Items.Any()) Items.Clear(); } - private List PopulateActions(List items,bool isQuery) - { - - foreach (var item in items) - { - if (item.QueryAction != null && item.ExecuteAction != null) continue; - if (isQuery && item.QueryAction == null) item.QueryAction = GetQueryAction(item.RawQuery); - if (!isQuery && item.ExecuteAction == null) item.ExecuteAction = GetExecuteAction(item.PluginID, item.RawQuery, item.Title, item.SubTitle); - } - - return items; - } - - private Func GetExecuteAction(string pluginId, string rawQuery, string title, string subTitle) - { - var plugin = PluginManager.GetPluginForId(pluginId); - - var query = QueryBuilder.Build(rawQuery, PluginManager.NonGlobalPlugins); - var freshResults = plugin.Plugin - .QueryAsync(query, CancellationToken.None) - .GetAwaiter() - .GetResult(); - return freshResults?.FirstOrDefault(r => r.Title == title - && r.SubTitle == subTitle)?.Action; - } - private Func GetQueryAction(string query) - { - return _=> - { - App.API.BackToQueryResults(); - App.API.ChangeQuery(query); - return false; - }; - } + private void AddLastQuery(Result result) { @@ -104,7 +73,7 @@ namespace Flow.Launcher.Storage { RawQuery = result.OriginQuery.RawQuery, ExecutedDateTime = DateTime.Now, - QueryAction = GetQueryAction(result.OriginQuery.RawQuery) + QueryAction = HistoryHelper.GetQueryAction(result.OriginQuery.RawQuery) }); } } diff --git a/Flow.Launcher/Storage/HistoryHelper.cs b/Flow.Launcher/Storage/HistoryHelper.cs new file mode 100644 index 000000000..9373a439c --- /dev/null +++ b/Flow.Launcher/Storage/HistoryHelper.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using Flow.Launcher.Core.Plugin; +using Flow.Launcher.Plugin; + +namespace Flow.Launcher.Storage; +public static class HistoryHelper +{ + internal static List PopulateActions(this List items, bool isQuery) + { + + foreach (var item in items) + { + if (item.QueryAction != null && item.ExecuteAction != null) continue; + if (isQuery && item.QueryAction == null) item.QueryAction = GetQueryAction(item.RawQuery); + if (!isQuery && item.ExecuteAction == null) item.ExecuteAction = GetExecuteAction(item.PluginID, item.RawQuery, item.Title, item.SubTitle); + } + + return items; + } + + private static Func GetExecuteAction(string pluginId, string rawQuery, string title, string subTitle) + { + var plugin = PluginManager.GetPluginForId(pluginId); + + var query = QueryBuilder.Build(rawQuery, PluginManager.NonGlobalPlugins); + var freshResults = plugin.Plugin + .QueryAsync(query, CancellationToken.None) + .GetAwaiter() + .GetResult(); + return freshResults?.FirstOrDefault(r => r.Title == title + && r.SubTitle == subTitle)?.Action; + } + public static Func GetQueryAction(string query) + { + return _ => + { + App.API.BackToQueryResults(); + App.API.ChangeQuery(query); + return false; + }; + } +} diff --git a/Flow.Launcher/Storage/HistoryItem.cs b/Flow.Launcher/Storage/HistoryItem.cs index 6a06a400a..04b97118e 100644 --- a/Flow.Launcher/Storage/HistoryItem.cs +++ b/Flow.Launcher/Storage/HistoryItem.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Text.Json.Serialization; using Flow.Launcher.Plugin; @@ -16,4 +17,6 @@ public class HistoryItem [JsonIgnore] public Func QueryAction { get; set; } + + }