mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Revert modifications and returning actions
This commit is contained in:
parent
a8d3cdf62c
commit
9ca7c8431b
5 changed files with 45 additions and 70 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<LastOpenedHistoryItem> LastOpenedHistoryItems { get; private set; } = [];
|
||||
|
||||
private readonly Settings _settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
|
||||
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
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1318,10 +1318,9 @@ namespace Flow.Launcher.ViewModel
|
|||
private List<Result> GetHistoryItems(IEnumerable<LastOpenedHistoryItem> historyItems)
|
||||
{
|
||||
var results = new List<Result>();
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue