Skip to content

Commit 44d8666

Browse files
committed
add warning for Windows Search service not turned on
1 parent 387c550 commit 44d8666

File tree

3 files changed

+46
-17
lines changed

3 files changed

+46
-17
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<system:String x:Key="plugin_explorer_deletefilefoldersuccess">Deletion successful</system:String>
1111
<system:String x:Key="plugin_explorer_deletefilefoldersuccess_detail">Successfully deleted the {0}</system:String>
1212
<system:String x:Key="plugin_explorer_globalActionKeywordInvalid">Assigning the global action keyword could bring up too many results during search. Please choose a specific action keyword</system:String>
13+
<system:String x:Key="plugin_explorer_windowsSearchServiceNotRunning">The required service for Windows Index Search does not appear to be running</system:String>
14+
<system:String x:Key="plugin_explorer_windowsSearchServiceFix">To fix this, start the Windows Search service. Select here to remove this warning</system:String>
1315

1416
<!--Controls-->
1517
<system:String x:Key="plugin_explorer_delete">Delete</system:String>

Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ namespace Flow.Launcher.Plugin.Explorer.Search
1212
{
1313
public class SearchManager
1414
{
15-
private readonly PluginInitContext context;
15+
internal static PluginInitContext Context;
1616

1717
private readonly Settings settings;
1818

1919
public SearchManager(Settings settings, PluginInitContext context)
2020
{
21-
this.context = context;
21+
Context = context;
2222
this.settings = settings;
2323
}
2424

@@ -99,7 +99,7 @@ public async Task<List<Result>> PathSearchAsync(Query query, CancellationToken t
9999
var isEnvironmentVariable = EnvironmentVariables.IsEnvironmentVariableSearch(querySearch);
100100

101101
if (isEnvironmentVariable)
102-
return EnvironmentVariables.GetEnvironmentStringPathSuggestions(querySearch, query, context);
102+
return EnvironmentVariables.GetEnvironmentStringPathSuggestions(querySearch, query, Context);
103103

104104
// Query is a location path with a full environment variable, eg. %appdata%\somefolder\
105105
var isEnvironmentVariablePath = querySearch[1..].Contains("%\\");
@@ -141,8 +141,9 @@ private async Task<List<Result>> WindowsIndexFileContentSearchAsync(Query query,
141141
if (string.IsNullOrEmpty(querySearchString))
142142
return new List<Result>();
143143

144-
return await IndexSearch.WindowsIndexSearchAsync(querySearchString,
145-
queryConstructor.CreateQueryHelper().ConnectionString,
144+
return await IndexSearch.WindowsIndexSearchAsync(
145+
querySearchString,
146+
queryConstructor.CreateQueryHelper,
146147
queryConstructor.QueryForFileContentSearch,
147148
settings.IndexSearchExcludedSubdirectoryPaths,
148149
query,
@@ -178,8 +179,9 @@ private async Task<List<Result>> WindowsIndexFilesAndFoldersSearchAsync(Query qu
178179
{
179180
var queryConstructor = new QueryConstructor(settings);
180181

181-
return await IndexSearch.WindowsIndexSearchAsync(querySearchString,
182-
queryConstructor.CreateQueryHelper().ConnectionString,
182+
return await IndexSearch.WindowsIndexSearchAsync(
183+
querySearchString,
184+
queryConstructor.CreateQueryHelper,
183185
queryConstructor.QueryForAllFilesAndFolders,
184186
settings.IndexSearchExcludedSubdirectoryPaths,
185187
query,
@@ -192,7 +194,7 @@ private async Task<List<Result>> WindowsIndexTopLevelFolderSearchAsync(Query que
192194
var queryConstructor = new QueryConstructor(settings);
193195

194196
return await IndexSearch.WindowsIndexSearchAsync(path,
195-
queryConstructor.CreateQueryHelper().ConnectionString,
197+
queryConstructor.CreateQueryHelper,
196198
queryConstructor.QueryForTopLevelDirectorySearch,
197199
settings.IndexSearchExcludedSubdirectoryPaths,
198200
query,

Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
using Flow.Launcher.Infrastructure.Logger;
21
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
32
using Microsoft.Search.Interop;
43
using System;
54
using System.Collections.Generic;
65
using System.Data.OleDb;
7-
using System.Linq;
6+
using System.Runtime.InteropServices;
87
using System.Text.RegularExpressions;
98
using System.Threading;
109
using System.Threading.Tasks;
@@ -84,7 +83,8 @@ internal static async Task<List<Result>> ExecuteWindowsIndexSearchAsync(string i
8483
return results;
8584
}
8685

87-
internal async static Task<List<Result>> WindowsIndexSearchAsync(string searchString, string connectionString,
86+
internal async static Task<List<Result>> WindowsIndexSearchAsync(string searchString,
87+
Func<CSearchQueryHelper> queryHelper,
8888
Func<string, string> constructQuery,
8989
List<AccessLink> exclusionList,
9090
Query query,
@@ -94,12 +94,29 @@ internal async static Task<List<Result>> WindowsIndexSearchAsync(string searchSt
9494

9595
if (regexMatch.Success)
9696
return new List<Result>();
97+
98+
try
99+
{
100+
var constructedQuery = constructQuery(searchString);
97101

98-
var constructedQuery = constructQuery(searchString);
99-
return RemoveResultsInExclusionList(
100-
await ExecuteWindowsIndexSearchAsync(constructedQuery, connectionString, query, token).ConfigureAwait(false),
102+
return RemoveResultsInExclusionList(
103+
await ExecuteWindowsIndexSearchAsync(constructedQuery, queryHelper().ConnectionString, query, token).ConfigureAwait(false),
101104
exclusionList,
102105
token);
106+
}
107+
catch (COMException)
108+
{
109+
// Occurs because the Windows Indexing (WSearch) is turned off in services and unable to be used by Explorer plugin
110+
return new List<Result>
111+
{
112+
new Result
113+
{
114+
Title = SearchManager.Context.API.GetTranslation("plugin_explorer_windowsSearchServiceNotRunning"),
115+
SubTitle = SearchManager.Context.API.GetTranslation("plugin_explorer_windowsSearchServiceFix"),
116+
IcoPath = Constants.ExplorerIconImagePath
117+
}
118+
};
119+
}
103120
}
104121

105122
private static List<Result> RemoveResultsInExclusionList(List<Result> results, List<AccessLink> exclusionList, CancellationToken token)
@@ -137,9 +154,17 @@ private static List<Result> RemoveResultsInExclusionList(List<Result> results, L
137154

138155
internal static bool PathIsIndexed(string path)
139156
{
140-
var csm = new CSearchManager();
141-
var indexManager = csm.GetCatalog("SystemIndex").GetCrawlScopeManager();
142-
return indexManager.IncludedInCrawlScope(path) > 0;
157+
try
158+
{
159+
var csm = new CSearchManager();
160+
var indexManager = csm.GetCatalog("SystemIndex").GetCrawlScopeManager();
161+
return indexManager.IncludedInCrawlScope(path) > 0;
162+
}
163+
catch(COMException)
164+
{
165+
// Occurs because the Windows Indexing (WSearch) is turned off in services and unable to be used by Explorer plugin
166+
return false;
167+
}
143168
}
144169

145170
private static void LogException(string message, Exception e)

0 commit comments

Comments
 (0)