From 355035eefa1ff4776508d738630b92c23faab282 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 1 Dec 2022 23:02:43 +1100 Subject: [PATCH] re-add warning when Windows Index service is off as a search result --- .../Exceptions/EngineNotAvailableException.cs | 6 ++-- .../Search/WindowsIndex/WindowsIndex.cs | 28 +++++++++++++------ .../WindowsIndex/WindowsIndexSearchManager.cs | 9 ++++-- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Exceptions/EngineNotAvailableException.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Exceptions/EngineNotAvailableException.cs index 340877bd1..1a48892f5 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Exceptions/EngineNotAvailableException.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Exceptions/EngineNotAvailableException.cs @@ -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> 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) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/WindowsIndex.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/WindowsIndex.cs index f7a4a019b..4396951d6 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/WindowsIndex.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/WindowsIndex.cs @@ -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 WindowsIndexSearchAsync(string connectionString, + internal static IAsyncEnumerable 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(); + 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; } } - - } } diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/WindowsIndexSearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/WindowsIndexSearchManager.cs index f736ca259..91ba2a858 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/WindowsIndexSearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/WindowsIndexSearchManager.cs @@ -21,7 +21,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex QueryHelper = QueryConstructor.CreateQueryHelper(); } - private IAsyncEnumerable WindowsIndexFileContentSearchAsync(ReadOnlySpan querySearchString, + private IAsyncEnumerable WindowsIndexFileContentSearchAsync( + ReadOnlySpan querySearchString, CancellationToken token) { if (querySearchString.IsEmpty) @@ -33,7 +34,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex token); } - private IAsyncEnumerable WindowsIndexFilesAndFoldersSearchAsync(ReadOnlySpan querySearchString, + private IAsyncEnumerable WindowsIndexFilesAndFoldersSearchAsync( + ReadOnlySpan querySearchString, CancellationToken token = default) { return WindowsIndex.WindowsIndexSearchAsync( @@ -42,7 +44,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex token); } - private IAsyncEnumerable WindowsIndexTopLevelFolderSearchAsync(ReadOnlySpan search, + private IAsyncEnumerable WindowsIndexTopLevelFolderSearchAsync( + ReadOnlySpan search, ReadOnlySpan path, bool recursive, CancellationToken token)