Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Flow.Launcher/Storage/LastOpenedHistoryItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ 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 string IcoPath { get; set; } = string.Empty;
public GlyphInfo Glyph { get; init; } = null;
public DateTime ExecutedDateTime { get; set; }

public bool Equals(Result r)
Expand Down
16 changes: 12 additions & 4 deletions Flow.Launcher/Storage/QueryHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public void Add(Result result)
LastOpenedHistoryItems.RemoveAt(0);
}

// If the last item is the same as the current result, just update the timestamp
if (LastOpenedHistoryItems.Count > 0 &&
LastOpenedHistoryItems.Last().Equals(result))
if (LastOpenedHistoryItems.Count > 0 &&
TryGetLastOpenedHistoryResult(result, out var existingHistoryItem))
{
LastOpenedHistoryItems.Last().ExecutedDateTime = DateTime.Now;
existingHistoryItem.IcoPath = result.IcoPath;
existingHistoryItem.ExecutedDateTime = DateTime.Now;
}
else
{
Expand All @@ -59,9 +59,17 @@ public void Add(Result result)
PluginID = result.PluginID,
Query = result.OriginQuery.RawQuery,
RecordKey = result.RecordKey,
IcoPath = result.IcoPath,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result.IcoPath should be absolute path which depends on Flow installed place, plugin version, Flow portable mode, etc. I think here we should use the relative path:

If this icon is inside the directory of the preinstalled plugins, let us store a relative path based on preinstalled plugin directory.

Else if the icon is inside the directory of the Flow data directory, let us store a relative path based on Flow data directory.

Else let us just use the absolute path.

Glyph = result.Glyph,
ExecutedDateTime = DateTime.Now
});
}
}

private bool TryGetLastOpenedHistoryResult(Result result, out LastOpenedHistoryItem historyItem)
{
historyItem = LastOpenedHistoryItems.FirstOrDefault(x => x.Equals(result));
return historyItem is not null;
}
}
}
66 changes: 41 additions & 25 deletions Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
using Flow.Launcher.Plugin;
using Flow.Launcher.Plugin.SharedCommands;
using Flow.Launcher.Storage;
using iNKORE.UI.WPF.Modern;

Check warning on line 27 in Flow.Launcher/ViewModel/MainViewModel.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`NKORE` is not a recognized word. (unrecognized-spelling)
using Microsoft.VisualStudio.Threading;

namespace Flow.Launcher.ViewModel
Expand Down Expand Up @@ -270,7 +270,7 @@
#if DEBUG
throw t.Exception;
#else
App.API.LogError(ClassName, $"Error happen in task dealing with viewupdate for results. {t.Exception}");

Check warning on line 273 in Flow.Launcher/ViewModel/MainViewModel.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`viewupdate` is not a recognized word. (unrecognized-spelling)
_resultsViewUpdateTask =
Task.Run(UpdateActionAsync).ContinueWith(continueAction, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.Default);
#endif
Expand Down Expand Up @@ -467,7 +467,7 @@
else if (!string.IsNullOrEmpty(SelectedResults.SelectedItem?.QuerySuggestionText))
{
//var defaultSuggestion = SelectedResults.SelectedItem.QuerySuggestionText;
//// check if result.actionkeywordassigned is empty

Check warning on line 470 in Flow.Launcher/ViewModel/MainViewModel.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`actionkeywordassigned` is not a recognized word. (unrecognized-spelling)
//if (!string.IsNullOrEmpty(result.ActionKeywordAssigned))
//{
// autoCompleteText = $"{result.ActionKeywordAssigned} {defaultSuggestion}";
Expand Down Expand Up @@ -1318,42 +1318,56 @@
private List<Result> GetHistoryItems(IEnumerable<LastOpenedHistoryItem> historyItems)
{
var results = new List<Result>();
if (Settings.HistoryStyle == HistoryStyle.Query)

if (Settings.HistoryStyle == HistoryStyle.LastOpened)
{
historyItems = historyItems
.GroupBy(r => new { r.Title, r.SubTitle, r.PluginID, r.RecordKey })
.Select(g => g.First());
}

foreach (var item in historyItems)
{
foreach (var h in historyItems)
Result result = null;
var glyph = item.Glyph is null && !string.IsNullOrEmpty(item.IcoPath) // Some plugins won't have Glyph, then prefer IcoPath
? null
: item.Glyph is not null
? item.Glyph
: new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\uE81C"); // Default fallback

var icoPath = !string.IsNullOrEmpty(item.IcoPath) ? item.IcoPath : Constant.HistoryIcon;

if (Settings.HistoryStyle == HistoryStyle.Query)
{
var result = new Result
result = new Result
{
Title = Localize.executeQuery(h.Query),
SubTitle = Localize.lastExecuteTime(h.ExecutedDateTime),
IcoPath = Constant.HistoryIcon,
OriginQuery = new Query { RawQuery = h.Query },
Title = Localize.executeQuery(item.Query),
SubTitle = Localize.lastExecuteTime(item.ExecutedDateTime),
IcoPath = icoPath,
OriginQuery = new Query { RawQuery = item.Query },
Action = _ =>
{
App.API.BackToQueryResults();
App.API.ChangeQuery(h.Query);
App.API.ChangeQuery(item.Query);
return false;
},
Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\uE81C")
Glyph = glyph
};
results.Add(result);
}
}
else
{
foreach (var h in historyItems)
else
{
var result = new Result

result = new Result
{
Title = string.IsNullOrEmpty(h.Title) ? // Old migrated history items have no title
Localize.executeQuery(h.Query) :
h.Title,
SubTitle = Localize.lastExecuteTime(h.ExecutedDateTime),
IcoPath = Constant.HistoryIcon,
OriginQuery = new Query { RawQuery = h.Query },
Title = string.IsNullOrEmpty(item.Title) ? // Old migrated history items have no title
Localize.executeQuery(item.Query) :
item.Title,
SubTitle = Localize.lastExecuteTime(item.ExecutedDateTime),
IcoPath = icoPath,
OriginQuery = new Query { RawQuery = item.Query },
AsyncAction = async c =>
{
var reflectResult = await ResultHelper.PopulateResultsAsync(h);
var reflectResult = await ResultHelper.PopulateResultsAsync(item);
if (reflectResult != null)
{
// Record the user selected record for result ranking
Expand All @@ -1366,14 +1380,16 @@

// If we cannot get the result, fallback to re-query
App.API.BackToQueryResults();
App.API.ChangeQuery(h.Query);
App.API.ChangeQuery(item.Query);
return false;
},
Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\uE81C")
Glyph = glyph
};
results.Add(result);
}

results.Add(result);
}

return results;
}

Expand Down
Loading