Skip to content

Commit 9ca7c84

Browse files
committed
Revert modifications and returning actions
1 parent a8d3cdf commit 9ca7c84

File tree

5 files changed

+45
-70
lines changed

5 files changed

+45
-70
lines changed

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,9 @@ public enum DialogJumpFileResultBehaviours
716716
public enum HistoryStyle
717717
{
718718
[EnumLocalizeKey(nameof(Localize.queryHistory))]
719-
Query = 1,
719+
Query,
720720

721721
[EnumLocalizeKey(nameof(Localize.executedHistory))]
722-
LastOpened = 2
722+
LastOpened
723723
}
724724
}

Flow.Launcher/Helper/ResultHelper.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Threading;
33
using System.Threading.Tasks;
44
using Flow.Launcher.Core.Plugin;
5-
using Flow.Launcher.Infrastructure.UserSettings;
65
using Flow.Launcher.Plugin;
76
using Flow.Launcher.Storage;
87

@@ -42,20 +41,4 @@ public static class ResultHelper
4241
return null;
4342
}
4443
}
45-
46-
public static bool IsEquals(this Result result, LastOpenedHistoryItem item, HistoryStyle style)
47-
{
48-
bool keyMatches = string.IsNullOrEmpty(result.RecordKey) && string.IsNullOrEmpty(item.RecordKey)
49-
? item.Title == result.Title
50-
: !string.IsNullOrEmpty(result.RecordKey) && !string.IsNullOrEmpty(item.RecordKey) && item.RecordKey == result.RecordKey;
51-
52-
bool queryMatches = style != HistoryStyle.Query || (result.OriginQuery != null && item.Query == result.OriginQuery.RawQuery);
53-
54-
55-
return keyMatches
56-
&& queryMatches
57-
&& item.SubTitle == result.SubTitle
58-
&& item.PluginID == result.PluginID
59-
&& item.HistoryStyle == style;
60-
}
6144
}

Flow.Launcher/Storage/LastOpenedHistoryItem.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using Flow.Launcher.Infrastructure.UserSettings;
32
using Flow.Launcher.Plugin;
43

54
namespace Flow.Launcher.Storage;
@@ -11,7 +10,22 @@ public class LastOpenedHistoryItem
1110
public string PluginID { get; set; } = string.Empty;
1211
public string Query { get; set; } = string.Empty;
1312
public string RecordKey { get; set; } = string.Empty;
14-
public HistoryStyle HistoryStyle { get; set; }
1513
public DateTime ExecutedDateTime { get; set; }
1614

15+
public bool Equals(Result r)
16+
{
17+
if (string.IsNullOrEmpty(RecordKey) || string.IsNullOrEmpty(r.RecordKey))
18+
{
19+
return Title == r.Title
20+
&& SubTitle == r.SubTitle
21+
&& PluginID == r.PluginID
22+
&& Query == r.OriginQuery.RawQuery;
23+
}
24+
else
25+
{
26+
return RecordKey == r.RecordKey
27+
&& PluginID == r.PluginID
28+
&& Query == r.OriginQuery.RawQuery;
29+
}
30+
}
1731
}

Flow.Launcher/Storage/QueryHistory.cs

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text.Json.Serialization;
5-
using CommunityToolkit.Mvvm.DependencyInjection;
6-
using Flow.Launcher.Helper;
7-
using Flow.Launcher.Infrastructure.UserSettings;
85
using Flow.Launcher.Plugin;
96

107
namespace Flow.Launcher.Storage
@@ -19,70 +16,51 @@ public class History
1916
[JsonInclude]
2017
public List<LastOpenedHistoryItem> LastOpenedHistoryItems { get; private set; } = [];
2118

22-
private readonly Settings _settings = Ioc.Default.GetRequiredService<Settings>();
23-
2419
private readonly int _maxHistory = 300;
2520

26-
2721
public void PopulateHistoryFromLegacyHistory()
2822
{
2923
if (Items.Count == 0) return;
3024
// Migrate old history items to new LastOpenedHistoryItems
3125
foreach (var item in Items)
3226
{
3327
LastOpenedHistoryItems.Add(new LastOpenedHistoryItem
34-
{
28+
{
3529
Query = item.Query,
36-
ExecutedDateTime = item.ExecutedDateTime,
37-
HistoryStyle = HistoryStyle.Query
30+
ExecutedDateTime = item.ExecutedDateTime
3831
});
3932
}
4033
Items.Clear();
4134
}
4235

4336
public void Add(Result result)
44-
{
37+
{
4538
if (string.IsNullOrEmpty(result.OriginQuery.RawQuery)) return;
46-
if (string.IsNullOrEmpty(result.PluginID)) return;
4739

48-
var style = _settings.HistoryStyle;
4940
// Maintain the max history limit
50-
if (LastOpenedHistoryItems.Count > _maxHistory)
41+
if (LastOpenedHistoryItems.Count > _maxHistory)
5142
{
5243
LastOpenedHistoryItems.RemoveAt(0);
5344
}
5445

5546
// If the last item is the same as the current result, just update the timestamp
56-
if (LastOpenedHistoryItems.Count > 0)
47+
if (LastOpenedHistoryItems.Count > 0 &&
48+
LastOpenedHistoryItems.Last().Equals(result))
5749
{
58-
var last = LastOpenedHistoryItems.Last();
59-
if (result.IsEquals(last, style))
60-
{
61-
last.ExecutedDateTime = DateTime.Now;
62-
return;
63-
}
64-
65-
var existItem = LastOpenedHistoryItems.FirstOrDefault(x => result.IsEquals(x, style));
66-
67-
if (existItem != null)
68-
{
69-
existItem.ExecutedDateTime = DateTime.Now;
70-
return;
71-
}
50+
LastOpenedHistoryItems.Last().ExecutedDateTime = DateTime.Now;
7251
}
73-
74-
LastOpenedHistoryItems.Add(new LastOpenedHistoryItem
52+
else
7553
{
76-
Title = result.Title,
77-
SubTitle = result.SubTitle,
78-
PluginID = result.PluginID,
79-
Query = result.OriginQuery.RawQuery,
80-
RecordKey = result.RecordKey,
81-
ExecutedDateTime = DateTime.Now,
82-
HistoryStyle = style
83-
});
54+
LastOpenedHistoryItems.Add(new LastOpenedHistoryItem
55+
{
56+
Title = result.Title,
57+
SubTitle = result.SubTitle,
58+
PluginID = result.PluginID,
59+
Query = result.OriginQuery.RawQuery,
60+
RecordKey = result.RecordKey,
61+
ExecutedDateTime = DateTime.Now
62+
});
63+
}
8464
}
85-
86-
8765
}
8866
}

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,10 +1318,9 @@ private void QueryHistory()
13181318
private List<Result> GetHistoryItems(IEnumerable<LastOpenedHistoryItem> historyItems)
13191319
{
13201320
var results = new List<Result>();
1321-
var historyItemsFiltered = historyItems.Where(x => x.HistoryStyle == Settings.HistoryStyle).ToList();
13221321
if (Settings.HistoryStyle == HistoryStyle.Query)
13231322
{
1324-
foreach (var h in historyItemsFiltered)
1323+
foreach (var h in historyItems)
13251324
{
13261325
var result = new Result
13271326
{
@@ -1342,7 +1341,7 @@ private List<Result> GetHistoryItems(IEnumerable<LastOpenedHistoryItem> historyI
13421341
}
13431342
else
13441343
{
1345-
foreach (var h in historyItemsFiltered)
1344+
foreach (var h in historyItems)
13461345
{
13471346
var result = new Result
13481347
{
@@ -1365,14 +1364,15 @@ private List<Result> GetHistoryItems(IEnumerable<LastOpenedHistoryItem> historyI
13651364
{
13661365
await reflectResult.AsyncAction(c);
13671366
}
1368-
13691367
return false;
13701368
}
1371-
1372-
App.API.BackToQueryResults();
1373-
App.API.ChangeQuery(h.Query);
1374-
return false;
1375-
},
1369+
else
1370+
{
1371+
App.API.BackToQueryResults();
1372+
App.API.ChangeQuery(h.Query);
1373+
return false;
1374+
}
1375+
},
13761376
Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\uE81C")
13771377
};
13781378
results.Add(result);

0 commit comments

Comments
 (0)