Code cleanup

This commit is contained in:
Jack251970 2025-10-13 15:30:38 +08:00
parent e3527f47ea
commit 7fa78f0304
4 changed files with 23 additions and 27 deletions

View file

@ -10,9 +10,14 @@ namespace Flow.Launcher.Storage
public class History
{
//Legacy
[JsonInclude] public List<HistoryItemLegacy> Items { get; private set; } = [];
[JsonInclude] public List<HistoryItem> LastOpenedHistoryItems { get; private set; } = [];
[JsonInclude] public List<HistoryItem> QueryHistoryItems { get; private set; } = [];
[JsonInclude]
public List<HistoryItemLegacy> Items { get; private set; } = [];
[JsonInclude]
public List<HistoryItem> LastOpenedHistoryItems { get; private set; } = [];
[JsonInclude]
public List<HistoryItem> QueryHistoryItems { get; private set; } = [];
private int _maxHistory = 300;
@ -20,7 +25,7 @@ namespace Flow.Launcher.Storage
{
if (!settings.ShowHistoryOnHomePage) return;
if (settings.ShowHistoryQueryResultsForHomePage)
{
{
AddLastQuery(result);
return;
}
@ -28,7 +33,7 @@ namespace Flow.Launcher.Storage
}
public List<HistoryItem> GetHistoryItems(Settings settings)
public List<HistoryItem> GetHistoryItems(Settings settings)
{
if (settings.ShowHistoryQueryResultsForHomePage) return QueryHistoryItems.PopulateActions(true);
return LastOpenedHistoryItems.PopulateActions(false);
@ -48,8 +53,6 @@ namespace Flow.Launcher.Storage
if (Items.Count > 0) Items.Clear();
}
private void AddLastQuery(Result result)
{
if (string.IsNullOrEmpty(result.OriginQuery.RawQuery)) return;
@ -83,11 +86,11 @@ namespace Flow.Launcher.Storage
RawQuery = result.OriginQuery.RawQuery,
RecordKey = result.RecordKey,
ExecutedDateTime = DateTime.Now,
ExecuteAction = result.Action
ExecuteAction = result.Action
};
var existing = LastOpenedHistoryItems.
FirstOrDefault(x => x.Title == item.Title && x.PluginID == item.PluginID);
FirstOrDefault(x => x.Title == item.Title && x.PluginID == item.PluginID);
if (existing != null)

View file

@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Flow.Launcher.Plugin;
namespace Flow.Launcher.Storage;
public class HistoryItem
{
public string Title { get; set; } = string.Empty;
@ -11,13 +11,11 @@ public class HistoryItem
public string PluginID { get; set; } = string.Empty;
public string RawQuery { get; set; }
public string RecordKey { get; set; } = string.Empty;
public DateTime ExecutedDateTime { get; set; }
[JsonIgnore]
public Func<ActionContext, bool> ExecuteAction { get; set; }
[JsonIgnore]
public Func<ActionContext, bool> QueryAction { get; set; }
}

View file

@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Flow.Launcher.Storage;
[Obsolete]
public class HistoryItemLegacy
{
public string Query { get; set; }
public DateTime? ExecutedDateTime { get; set; }
}

View file

@ -8,8 +8,8 @@ using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using CommunityToolkit.Mvvm.DependencyInjection;
@ -1280,9 +1280,9 @@ namespace Flow.Launcher.ViewModel
if (!match.IsSearchPrecisionScoreMet()) return false;
r.Score = match.Score;
return true;
}).ToList();
r.Score = match.Score;
return true;
}).ToList();
ContextMenu.AddResults(filtered, id);
}
else
@ -1308,7 +1308,7 @@ namespace Flow.Launcher.ViewModel
(
r => App.API.FuzzySearch(query, r.Title).IsSearchPrecisionScoreMet() ||
App.API.FuzzySearch(query, r.SubTitle).IsSearchPrecisionScoreMet()
).ToList();
).ToList();
History.AddResults(filtered, id);
}
else
@ -1320,7 +1320,6 @@ namespace Flow.Launcher.ViewModel
private List<Result> GetHistoryResults(IEnumerable<HistoryItem> historyItems)
{
var results = new List<Result>();
foreach (var h in historyItems)
{
var result = new Result
@ -1336,11 +1335,10 @@ namespace Flow.Launcher.ViewModel
};
results.Add(result);
}
return results;
}
private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, bool reSelect = true)
private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, bool reSelect = true)
{
_updateSource?.Cancel();