Skip to content

Commit cd49464

Browse files
committed
Make clear results local & Improve code quality
1 parent 4676234 commit cd49464

File tree

1 file changed

+48
-50
lines changed

1 file changed

+48
-50
lines changed

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,23 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
14411441
}
14421442

14431443
// Local function
1444+
void ClearResults()
1445+
{
1446+
App.API.LogDebug(ClassName, $"Clear query results");
1447+
1448+
// Hide and clear results again because running query may show and add some results
1449+
Results.Visibility = Visibility.Collapsed;
1450+
Results.Clear();
1451+
1452+
// Reset plugin icon
1453+
PluginIconPath = null;
1454+
PluginIconSource = null;
1455+
SearchIconVisibility = Visibility.Visible;
1456+
1457+
// Hide progress bar again because running query may set this to visible
1458+
ProgressBarVisibility = Visibility.Hidden;
1459+
}
1460+
14441461
async Task QueryTaskAsync(PluginPair plugin, CancellationToken token)
14451462
{
14461463
App.API.LogDebug(ClassName, $"Wait for querying plugin <{plugin.Metadata.Name}>");
@@ -1458,48 +1475,46 @@ async Task QueryTaskAsync(PluginPair plugin, CancellationToken token)
14581475
// Task.Yield will force it to run in ThreadPool
14591476
await Task.Yield();
14601477

1461-
{
1462-
IReadOnlyList<Result> results = currentIsQuickSwitch ?
1463-
await PluginManager.QueryQuickSwitchForPluginAsync(plugin, query, token) :
1464-
currentIsHomeQuery ?
1465-
await PluginManager.QueryHomeForPluginAsync(plugin, query, token) :
1466-
await PluginManager.QueryForPluginAsync(plugin, query, token);
1478+
IReadOnlyList<Result> results = currentIsQuickSwitch ?
1479+
await PluginManager.QueryQuickSwitchForPluginAsync(plugin, query, token) :
1480+
currentIsHomeQuery ?
1481+
await PluginManager.QueryHomeForPluginAsync(plugin, query, token) :
1482+
await PluginManager.QueryForPluginAsync(plugin, query, token);
14671483

1468-
if (token.IsCancellationRequested) return;
1484+
if (token.IsCancellationRequested) return;
14691485

1470-
IReadOnlyList<Result> resultsCopy;
1471-
if (results == null)
1472-
{
1473-
resultsCopy = _emptyResult;
1474-
}
1475-
else
1476-
{
1477-
// make a copy of results to avoid possible issue that FL changes some properties of the records, like score, etc.
1478-
resultsCopy = DeepCloneResults(results, currentIsQuickSwitch, token);
1479-
}
1486+
IReadOnlyList<Result> resultsCopy;
1487+
if (results == null)
1488+
{
1489+
resultsCopy = _emptyResult;
1490+
}
1491+
else
1492+
{
1493+
// make a copy of results to avoid possible issue that FL changes some properties of the records, like score, etc.
1494+
resultsCopy = DeepCloneResults(results, currentIsQuickSwitch, token);
1495+
}
14801496

1481-
foreach (var result in resultsCopy)
1497+
foreach (var result in resultsCopy)
1498+
{
1499+
if (string.IsNullOrEmpty(result.BadgeIcoPath))
14821500
{
1483-
if (string.IsNullOrEmpty(result.BadgeIcoPath))
1484-
{
1485-
result.BadgeIcoPath = plugin.Metadata.IcoPath;
1486-
}
1501+
result.BadgeIcoPath = plugin.Metadata.IcoPath;
14871502
}
1503+
}
14881504

1489-
if (token.IsCancellationRequested) return;
1505+
if (token.IsCancellationRequested) return;
14901506

1491-
App.API.LogDebug(ClassName, $"Update results for plugin <{plugin.Metadata.Name}>");
1507+
App.API.LogDebug(ClassName, $"Update results for plugin <{plugin.Metadata.Name}>");
14921508

1493-
// Indicate if to clear existing results so to show only ones from plugins with action keywords
1494-
var shouldClearExistingResults = ShouldClearExistingResults(query, currentIsHomeQuery);
1495-
_lastQuery = query;
1496-
_previousIsHomeQuery = currentIsHomeQuery;
1509+
// Indicate if to clear existing results so to show only ones from plugins with action keywords
1510+
var shouldClearExistingResults = ShouldClearExistingResults(query, currentIsHomeQuery);
1511+
_lastQuery = query;
1512+
_previousIsHomeQuery = currentIsHomeQuery;
14971513

1498-
if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(resultsCopy, plugin.Metadata, query,
1499-
token, reSelect, shouldClearExistingResults)))
1500-
{
1501-
App.API.LogError(ClassName, "Unable to add item to Result Update Queue");
1502-
}
1514+
if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(resultsCopy, plugin.Metadata, query,
1515+
token, reSelect, shouldClearExistingResults)))
1516+
{
1517+
App.API.LogError(ClassName, "Unable to add item to Result Update Queue");
15031518
}
15041519
}
15051520

@@ -1522,23 +1537,6 @@ void QueryHistoryTask(CancellationToken token)
15221537
}
15231538
}
15241539

1525-
private void ClearResults()
1526-
{
1527-
App.API.LogDebug(ClassName, $"Clear query results");
1528-
1529-
// Hide and clear results again because running query may show and add some results
1530-
Results.Visibility = Visibility.Collapsed;
1531-
Results.Clear();
1532-
1533-
// Reset plugin icon
1534-
PluginIconPath = null;
1535-
PluginIconSource = null;
1536-
SearchIconVisibility = Visibility.Visible;
1537-
1538-
// Hide progress bar again because running query may set this to visible
1539-
ProgressBarVisibility = Visibility.Hidden;
1540-
}
1541-
15421540
private async Task<Query> ConstructQueryAsync(string queryText, IEnumerable<CustomShortcutModel> customShortcuts,
15431541
IEnumerable<BaseBuiltinShortcutModel> builtInShortcuts)
15441542
{

0 commit comments

Comments
 (0)