Skip to content
Closed
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
7 changes: 7 additions & 0 deletions Plugins/Flow.Launcher.Plugin.Explorer/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Flow.Launcher.Plugin.Explorer.ViewModels;
using Flow.Launcher.Plugin.Explorer.Views;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Controls;

namespace Flow.Launcher.Plugin.Explorer
Expand All @@ -17,6 +18,9 @@ public class Main : ISettingProvider, IPlugin, ISavable, IContextMenu, IPluginI1

private IContextMenu contextMenu;

private static CancellationTokenSource updateSource;
public static CancellationToken updateToken;

public Control CreateSettingPanel()
{
return new ExplorerSettings(viewModel);
Expand All @@ -37,6 +41,9 @@ public List<Result> LoadContextMenus(Result selectedResult)

public List<Result> Query(Query query)
{
updateSource?.Cancel();
updateSource = new CancellationTokenSource();
updateToken = updateSource.Token;
return new SearchManager(Settings, Context).Search(query);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
using Microsoft.Search.Interop;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.OleDb;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
{
Expand All @@ -15,7 +18,7 @@ internal class IndexSearch
private OleDbConnection conn;

private OleDbCommand command;

private OleDbDataReader dataReaderResults;

private readonly ResultManager resultManager;
Expand All @@ -28,7 +31,7 @@ internal IndexSearch(PluginInitContext context)
resultManager = new ResultManager(context);
}

internal List<Result> ExecuteWindowsIndexSearch(string indexQueryString, string connectionString, Query query)
internal async Task<List<Result>> ExecuteWindowsIndexSearch(string indexQueryString, string connectionString, Query query)
{
var folderResults = new List<Result>();
var fileResults = new List<Result>();
Expand All @@ -43,8 +46,11 @@ internal List<Result> ExecuteWindowsIndexSearch(string indexQueryString, string
using (command = new OleDbCommand(indexQueryString, conn))
{
// Results return as an OleDbDataReader.
using (dataReaderResults = command.ExecuteReader())
var updateToken = Main.updateToken;
using (dataReaderResults = await command.ExecuteReaderAsync(updateToken).ConfigureAwait(false) as OleDbDataReader)
{
if (updateToken.IsCancellationRequested)
return new List<Result>();
if (dataReaderResults.HasRows)
{
while (dataReaderResults.Read())
Expand All @@ -55,15 +61,15 @@ internal List<Result> ExecuteWindowsIndexSearch(string indexQueryString, string
var encodedFragmentPath = dataReaderResults
.GetString(1)
.Replace("#", "%23", StringComparison.OrdinalIgnoreCase);

var path = new Uri(encodedFragmentPath).LocalPath;

if (dataReaderResults.GetString(2) == "Directory")
{
folderResults.Add(resultManager.CreateFolderResult(
dataReaderResults.GetString(0),
path,
path,
path,
query, true, true));
}
else
Expand All @@ -87,7 +93,7 @@ internal List<Result> ExecuteWindowsIndexSearch(string indexQueryString, string
LogException("General error from performing index search", e);
}

// Intial ordering, this order can be updated later by UpdateResultView.MainViewModel based on history of user selection.
// Initial ordering, this order can be updated later by UpdateResultView.MainViewModel based on history of user selection.
return results.Concat(folderResults.OrderBy(x => x.Title)).Concat(fileResults.OrderBy(x => x.Title)).ToList(); ;
}

Expand All @@ -101,7 +107,7 @@ internal List<Result> WindowsIndexSearch(string searchString, string connectionS
lock (_lock)
{
var constructedQuery = constructQuery(searchString);
return ExecuteWindowsIndexSearch(constructedQuery, connectionString, query);
return ExecuteWindowsIndexSearch(constructedQuery, connectionString, query).GetAwaiter().GetResult();
}
}

Expand Down