From 0b05e954e5d2dcf949e4a5d9332849ca90be86b7 Mon Sep 17 00:00:00 2001 From: Ioannis G Date: Tue, 6 Jun 2023 12:57:44 +0300 Subject: [PATCH] add `Query.IsForced` property When a plugin is processing a query, it can check the `IsForced` property to decide if the results will be served from cache or not. --- Flow.Launcher.Plugin/Query.cs | 6 ++++++ Flow.Launcher/ViewModel/MainViewModel.cs | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher.Plugin/Query.cs b/Flow.Launcher.Plugin/Query.cs index 95547d273..615729b61 100644 --- a/Flow.Launcher.Plugin/Query.cs +++ b/Flow.Launcher.Plugin/Query.cs @@ -29,6 +29,12 @@ namespace Flow.Launcher.Plugin /// public string RawQuery { get; internal init; } + /// + /// Determines whether the query was forced to execute again. + /// When this property is true, plugins handling this query should avoid serving cached results. + /// + public bool IsForced { get; internal set; } = false; + /// /// Search part of a query. /// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as RawQuery. diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 8529df7b3..5d21341e3 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -512,7 +512,7 @@ namespace Flow.Launcher.ViewModel } else if (reQuery) { - Query(); + Query(reQuery: true); } QueryTextCursorMovedToEnd = true; }); @@ -612,11 +612,11 @@ namespace Flow.Launcher.ViewModel #region Query - public void Query() + public void Query(bool reQuery = false) { if (SelectedIsFromQueryResults()) { - QueryResults(); + QueryResults(reQuery); } else if (ContextMenuSelected()) { @@ -716,7 +716,7 @@ namespace Flow.Launcher.ViewModel private readonly IReadOnlyList _emptyResult = new List(); - private async void QueryResults() + private async void QueryResults(bool reQuery = false) { _updateSource?.Cancel(); @@ -747,6 +747,8 @@ namespace Flow.Launcher.ViewModel if (currentCancellationToken.IsCancellationRequested) return; + // Update the query's IsForced property to true if this is a re-query + query.IsForced = reQuery; // handle the exclusiveness of plugin using action keyword RemoveOldQueryResults(query);