From dea168924db87d76c9bb7351ccab4e1766977c81 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Thu, 8 Jul 2021 01:38:57 +0800 Subject: [PATCH] fix unexpected different token due to default --- Flow.Launcher/ViewModel/MainViewModel.cs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index b0bd49657..2fd00224c 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -135,13 +135,17 @@ namespace Flow.Launcher.ViewModel var plugin = (IResultUpdated)pair.Plugin; plugin.ResultsUpdated += (s, e) => { - if (e.Query.RawQuery == QueryText && !e.Token.IsCancellationRequested) + if (e.Query.RawQuery != QueryText || e.Token.IsCancellationRequested) { - PluginManager.UpdatePluginMetadata(e.Results, pair.Metadata, e.Query); - if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(e.Results, pair.Metadata, e.Query, e.Token))) - { - Log.Error("MainViewModel", "Unable to add item to Result Update Queue"); - } + return; + } + + var token = e.Token == default ? _updateToken : e.Token; + + PluginManager.UpdatePluginMetadata(e.Results, pair.Metadata, e.Query); + if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(e.Results, pair.Metadata, e.Query, token))) + { + Log.Error("MainViewModel", "Unable to add item to Result Update Queue"); } }; } @@ -459,7 +463,7 @@ namespace Flow.Launcher.ViewModel } private readonly IReadOnlyList _emptyResult = new List(); - + private async void QueryResults() { _updateSource?.Cancel(); @@ -553,7 +557,7 @@ namespace Flow.Launcher.ViewModel await Task.Yield(); IReadOnlyList results = await PluginManager.QueryForPluginAsync(plugin, query, currentCancellationToken); - + currentCancellationToken.ThrowIfCancellationRequested(); results ??= _emptyResult;