re-add warning when Windows Index service is off as a search result

This commit is contained in:
Jeremy 2022-12-01 23:02:43 +11:00
parent 5ac2366697
commit 355035eefa
3 changed files with 29 additions and 14 deletions

View file

@ -16,7 +16,8 @@ public class EngineNotAvailableException : Exception
public string? ErrorIcon { get; init; }
public EngineNotAvailableException(string engineName,
public EngineNotAvailableException(
string engineName,
string resolution,
string message,
Func<ActionContext, ValueTask<bool>> action = null) : base(message)
@ -30,7 +31,8 @@ public class EngineNotAvailableException : Exception
});
}
public EngineNotAvailableException(string engineName,
public EngineNotAvailableException(
string engineName,
string resolution,
string message,
Exception innerException) : base(message, innerException)

View file

@ -70,9 +70,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
// Initial ordering, this order can be updated later by UpdateResultView.MainViewModel based on history of user selection.
}
internal static IAsyncEnumerable<SearchResult> WindowsIndexSearchAsync(string connectionString,
internal static IAsyncEnumerable<SearchResult> WindowsIndexSearchAsync(
string connectionString,
string search,
CancellationToken token)
{
@ -87,21 +86,34 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
{
throw new SearchException("Windows Index", e.Message, e);
}
catch (COMException e)
catch (COMException)
{
// Occurs because the Windows Indexing (WSearch) is turned off in services and unable to be used by Explorer plugin
if (!SearchManager.Settings.WarnWindowsSearchServiceOff)
return AsyncEnumerable.Empty<SearchResult>();
var api = SearchManager.Context.API;
throw new EngineNotAvailableException("Windows Index",
throw new EngineNotAvailableException(
"Windows Index",
api.GetTranslation("plugin_explorer_windowsSearchServiceFix"),
api.GetTranslation("plugin_explorer_windowsSearchServiceNotRunning"),
e)
c =>
{
SearchManager.Settings.WarnWindowsSearchServiceOff = false;
// Clears the warning message so user is not mistaken that it has not worked
api.ChangeQuery(string.Empty);
return ValueTask.FromResult(false);
})
{
ErrorIcon = Constants.WindowsIndexErrorImagePath
};
}
}
internal static bool PathIsIndexed(string path)
{
try
@ -116,7 +128,5 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
return false;
}
}
}
}

View file

@ -21,7 +21,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
QueryHelper = QueryConstructor.CreateQueryHelper();
}
private IAsyncEnumerable<SearchResult> WindowsIndexFileContentSearchAsync(ReadOnlySpan<char> querySearchString,
private IAsyncEnumerable<SearchResult> WindowsIndexFileContentSearchAsync(
ReadOnlySpan<char> querySearchString,
CancellationToken token)
{
if (querySearchString.IsEmpty)
@ -33,7 +34,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
token);
}
private IAsyncEnumerable<SearchResult> WindowsIndexFilesAndFoldersSearchAsync(ReadOnlySpan<char> querySearchString,
private IAsyncEnumerable<SearchResult> WindowsIndexFilesAndFoldersSearchAsync(
ReadOnlySpan<char> querySearchString,
CancellationToken token = default)
{
return WindowsIndex.WindowsIndexSearchAsync(
@ -42,7 +44,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
token);
}
private IAsyncEnumerable<SearchResult> WindowsIndexTopLevelFolderSearchAsync(ReadOnlySpan<char> search,
private IAsyncEnumerable<SearchResult> WindowsIndexTopLevelFolderSearchAsync(
ReadOnlySpan<char> search,
ReadOnlySpan<char> path,
bool recursive,
CancellationToken token)