From 6ed5308896762787971ff6e085ac2995b50bcfdf Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 11 May 2025 16:53:44 +0800 Subject: [PATCH 1/2] Fix null origin query issue --- Flow.Launcher/Storage/TopMostRecord.cs | 18 +----------------- Flow.Launcher/ViewModel/MainViewModel.cs | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/Flow.Launcher/Storage/TopMostRecord.cs b/Flow.Launcher/Storage/TopMostRecord.cs index 7f35904a520..327ad8336d0 100644 --- a/Flow.Launcher/Storage/TopMostRecord.cs +++ b/Flow.Launcher/Storage/TopMostRecord.cs @@ -12,9 +12,7 @@ public class TopMostRecord internal bool IsTopMost(Result result) { - // origin query is null when user select the context menu item directly of one item from query list - // in this case, we do not need to check if the result is top most - if (records.IsEmpty || result.OriginQuery == null || + if (records.IsEmpty || !records.TryGetValue(result.OriginQuery.RawQuery, out var value)) { return false; @@ -26,25 +24,11 @@ internal bool IsTopMost(Result result) internal void Remove(Result result) { - // origin query is null when user select the context menu item directly of one item from query list - // in this case, we do not need to remove the record - if (result.OriginQuery == null) - { - return; - } - records.Remove(result.OriginQuery.RawQuery, out _); } internal void AddOrUpdate(Result result) { - // origin query is null when user select the context menu item directly of one item from query list - // in this case, we do not need to add or update the record - if (result.OriginQuery == null) - { - return; - } - var record = new Record { PluginID = result.PluginID, diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 0c299875fdf..efa6dd39d20 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -444,12 +444,7 @@ private async Task OpenResultAsync(string index) if (QueryResultsSelected()) { _userSelectedRecord.Add(result); - // origin query is null when user select the context menu item directly of one item from query list - // so we don't want to add it to history - if (result.OriginQuery != null) - { - _history.Add(result.OriginQuery.RawQuery); - } + _history.Add(result.OriginQuery.RawQuery); lastHistoryIndex = 1; } @@ -1158,7 +1153,7 @@ private void QueryContextMenu() { results = PluginManager.GetContextMenusForPlugin(selected); results.Add(ContextMenuTopMost(selected)); - results.Add(ContextMenuPluginInfo(selected.PluginID)); + results.Add(ContextMenuPluginInfo(selected)); } if (!string.IsNullOrEmpty(query)) @@ -1592,7 +1587,8 @@ private Result ContextMenuTopMost(Result result) App.API.ReQuery(); return false; }, - Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\uE74B") + Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\uE74B"), + OriginQuery = result.OriginQuery }; } else @@ -1609,15 +1605,17 @@ private Result ContextMenuTopMost(Result result) App.API.ReQuery(); return false; }, - Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\uE74A") + Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\uE74A"), + OriginQuery = result.OriginQuery }; } return menu; } - private static Result ContextMenuPluginInfo(string id) + private static Result ContextMenuPluginInfo(Result result) { + var id = result.PluginID; var metadata = PluginManager.GetPluginForId(id).Metadata; var translator = App.API; @@ -1639,7 +1637,8 @@ private static Result ContextMenuPluginInfo(string id) { App.API.OpenUrl(metadata.Website); return true; - } + }, + OriginQuery = result.OriginQuery }; return menu; } From 0e6741cf3f7d6960df13fc7a53a24c8e8963a47d Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 11 May 2025 17:05:55 +0800 Subject: [PATCH 2/2] Improve code quality --- Flow.Launcher/Storage/TopMostRecord.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Flow.Launcher/Storage/TopMostRecord.cs b/Flow.Launcher/Storage/TopMostRecord.cs index 327ad8336d0..7714b500146 100644 --- a/Flow.Launcher/Storage/TopMostRecord.cs +++ b/Flow.Launcher/Storage/TopMostRecord.cs @@ -12,8 +12,7 @@ public class TopMostRecord internal bool IsTopMost(Result result) { - if (records.IsEmpty || - !records.TryGetValue(result.OriginQuery.RawQuery, out var value)) + if (records.IsEmpty || !records.TryGetValue(result.OriginQuery.RawQuery, out var value)) { return false; }