Skip to content

Commit 8fdbae6

Browse files
Jack251970TBM13
authored andcommitted
Merge pull request Flow-Launcher#4042 from 01Dri/feature/history_mode
Add "Last opened" history mode & Fix non-result history item save issue
1 parent 7ca2ce1 commit 8fdbae6

File tree

6 files changed

+87
-9
lines changed

6 files changed

+87
-9
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
33
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
4-
<!-- Work around https://github.com/dotnet/runtime/issues/109682 -->
4+
<!-- Workaround https://github.com/dotnet/runtime/issues/109682 -->
55
<CETCompat>false</CETCompat>
66
</PropertyGroup>
77
</Project>

Flow.Launcher/Flow.Launcher.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
</Target>
172172

173173
<Target Name="RemoveDuplicateAnalyzers" BeforeTargets="CoreCompile">
174-
<!-- Work around https://github.com/dotnet/wpf/issues/6792 -->
174+
<!-- Workaround https://github.com/dotnet/wpf/issues/6792 -->
175175
<ItemGroup>
176176
<FilteredAnalyzer Include="@(Analyzer-&gt;Distinct())" />
177177
<Analyzer Remove="@(Analyzer)" />
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Linq;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using Flow.Launcher.Core.Plugin;
5+
using Flow.Launcher.Plugin;
6+
using Flow.Launcher.Storage;
7+
8+
namespace Flow.Launcher.Helper;
9+
10+
#nullable enable
11+
12+
public static class ResultHelper
13+
{
14+
public static async Task<Result?> PopulateResultsAsync(LastOpenedHistoryItem item)
15+
{
16+
return await PopulateResultsAsync(item.PluginID, item.Query, item.Title, item.SubTitle, item.RecordKey);
17+
}
18+
19+
public static async Task<Result?> PopulateResultsAsync(string pluginId, string rawQuery, string title, string subTitle, string recordKey)
20+
{
21+
var plugin = PluginManager.GetPluginForId(pluginId);
22+
if (plugin == null) return null;
23+
var query = QueryBuilder.Build(rawQuery, PluginManager.NonGlobalPlugins);
24+
if (query == null) return null;
25+
try
26+
{
27+
var freshResults = await plugin.Plugin.QueryAsync(query, CancellationToken.None);
28+
// Try to match by record key first if it is valid, otherwise fall back to title + subtitle match
29+
if (string.IsNullOrEmpty(recordKey))
30+
{
31+
return freshResults?.FirstOrDefault(r => r.Title == title && r.SubTitle == subTitle);
32+
}
33+
else
34+
{
35+
return freshResults?.FirstOrDefault(r => r.RecordKey == recordKey) ??
36+
freshResults?.FirstOrDefault(r => r.Title == title && r.SubTitle == subTitle);
37+
}
38+
}
39+
catch (System.Exception e)
40+
{
41+
App.API.LogException(nameof(ResultHelper), $"Failed to query results for {plugin.Metadata.Name}", e);
42+
return null;
43+
}
44+
}
45+
}

Flow.Launcher/Languages/en.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@
162162
<system:String x:Key="homePageToolTip">Show home page results when query text is empty.</system:String>
163163
<system:String x:Key="historyResultsForHomePage">Show History Results in Home Page</system:String>
164164
<system:String x:Key="historyResultsCountForHomePage">Maximum History Results Shown in Home Page</system:String>
165+
<system:String x:Key="historyStyle">History Style</system:String>
166+
<system:String x:Key="historyStyleTooltip">Choose the type of history to show in the History and Home Page</system:String>
167+
<system:String x:Key="queryHistory">Query history</system:String>
168+
<system:String x:Key="executedHistory">Last opened history</system:String>
165169
<system:String x:Key="homeToggleBoxToolTip">This can only be edited if plugin supports Home feature and Home Page is enabled.</system:String>
166170
<system:String x:Key="showAtTopmost">Show Search Window at Foremost</system:String>
167171
<system:String x:Key="showAtTopmostToolTip">Overrides other programs' 'Always on Top' setting and displays Flow in the foremost position.</system:String>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using Flow.Launcher.Plugin;
3+
4+
namespace Flow.Launcher.Storage;
5+
6+
public class LastOpenedHistoryItem
7+
{
8+
public string Title { get; set; } = string.Empty;
9+
public string SubTitle { get; set; } = string.Empty;
10+
public string PluginID { get; set; } = string.Empty;
11+
public string Query { get; set; } = string.Empty;
12+
public string RecordKey { get; set; } = string.Empty;
13+
public DateTime ExecutedDateTime { get; set; }
14+
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+
}
31+
}

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using CommunityToolkit.Mvvm.DependencyInjection;
1616
using CommunityToolkit.Mvvm.Input;
1717
using Flow.Launcher.Core.Plugin;
18+
using Flow.Launcher.Helper;
1819
using Flow.Launcher.Infrastructure;
1920
using Flow.Launcher.Infrastructure.Hotkey;
2021
using Flow.Launcher.Infrastructure.Storage;
@@ -381,18 +382,15 @@ private async Task OpenResultAsync(string index)
381382
{
382383
// not null means pressing modifier key + number, should ignore the modifier key
383384
SpecialKeyState = index is not null ? SpecialKeyState.Default : GlobalHotkey.CheckModifiers()
384-
})
385-
.ConfigureAwait(false);
386-
387-
if (QueryResultsSelected())
388-
{
389-
_userSelectedRecord.Add(result);
390-
}
385+
}).ConfigureAwait(false);
391386

392387
if (hideWindow)
393388
{
394389
Hide();
395390
}
391+
392+
// Record user selected result for result ranking
393+
_userSelectedRecord.Add(result);
396394
}
397395

398396
private static IReadOnlyList<Result> DeepCloneResults(IReadOnlyList<Result> results, CancellationToken token = default)

0 commit comments

Comments
 (0)