add option to remove warning msg and install Everything plugin

This commit is contained in:
Jeremy Wu 2021-07-25 19:58:21 +10:00
parent 44d8666e27
commit 86fe664404
4 changed files with 60 additions and 23 deletions

View file

@ -12,6 +12,8 @@
<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>
<system:String x:Key="plugin_explorer_windowsSearchServiceNotRunning">The required service for Windows Index Search does not appear to be running</system:String>
<system:String x:Key="plugin_explorer_windowsSearchServiceFix">To fix this, start the Windows Search service. Select here to remove this warning</system:String>
<system:String x:Key="plugin_explorer_alternative">The warning message has been switched off. As an alternative for searching files and folders, would you like to install Everything plugin?{0}{0}Select 'Yes' to install Everything plugin, or 'No' to return</system:String>
<system:String x:Key="plugin_explorer_alternative_title">Explorer Alternative</system:String>
<!--Controls-->
<system:String x:Key="plugin_explorer_delete">Delete</system:String>

View file

@ -14,12 +14,12 @@ namespace Flow.Launcher.Plugin.Explorer.Search
{
internal static PluginInitContext Context;
private readonly Settings settings;
internal static Settings Settings;
public SearchManager(Settings settings, PluginInitContext context)
{
Context = context;
this.settings = settings;
Settings = settings;
}
private class PathEqualityComparator : IEqualityComparer<Result>
@ -71,14 +71,14 @@ namespace Flow.Launcher.Plugin.Explorer.Search
return allowedActionKeyword switch
{
Settings.ActionKeyword.SearchActionKeyword => settings.SearchActionKeywordEnabled &&
keyword == settings.SearchActionKeyword,
Settings.ActionKeyword.PathSearchActionKeyword => settings.PathSearchKeywordEnabled &&
keyword == settings.PathSearchActionKeyword,
Settings.ActionKeyword.SearchActionKeyword => Settings.SearchActionKeywordEnabled &&
keyword == Settings.SearchActionKeyword,
Settings.ActionKeyword.PathSearchActionKeyword => Settings.PathSearchKeywordEnabled &&
keyword == Settings.PathSearchActionKeyword,
Settings.ActionKeyword.FileContentSearchActionKeyword => keyword ==
settings.FileContentSearchActionKeyword,
Settings.ActionKeyword.IndexSearchActionKeyword => settings.IndexOnlySearchKeywordEnabled &&
keyword == settings.IndexSearchActionKeyword
Settings.FileContentSearchActionKeyword,
Settings.ActionKeyword.IndexSearchActionKeyword => Settings.IndexOnlySearchKeywordEnabled &&
keyword == Settings.IndexSearchActionKeyword
};
}
@ -88,11 +88,11 @@ namespace Flow.Launcher.Plugin.Explorer.Search
// This allows the user to type the assigned action keyword and only see the list of quick folder links
if (string.IsNullOrEmpty(query.Search))
return QuickAccess.AccessLinkListAll(query, settings.QuickAccessLinks);
return QuickAccess.AccessLinkListAll(query, Settings.QuickAccessLinks);
var results = new HashSet<Result>(PathEqualityComparator.Instance);
var quickaccessLinks = QuickAccess.AccessLinkListMatched(query, settings.QuickAccessLinks);
var quickaccessLinks = QuickAccess.AccessLinkListMatched(query, Settings.QuickAccessLinks);
results.UnionWith(quickaccessLinks);
@ -136,7 +136,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
private async Task<List<Result>> WindowsIndexFileContentSearchAsync(Query query, string querySearchString,
CancellationToken token)
{
var queryConstructor = new QueryConstructor(settings);
var queryConstructor = new QueryConstructor(Settings);
if (string.IsNullOrEmpty(querySearchString))
return new List<Result>();
@ -145,14 +145,14 @@ namespace Flow.Launcher.Plugin.Explorer.Search
querySearchString,
queryConstructor.CreateQueryHelper,
queryConstructor.QueryForFileContentSearch,
settings.IndexSearchExcludedSubdirectoryPaths,
Settings.IndexSearchExcludedSubdirectoryPaths,
query,
token).ConfigureAwait(false);
}
public bool IsFileContentSearch(string actionKeyword)
{
return actionKeyword == settings.FileContentSearchActionKeyword;
return actionKeyword == Settings.FileContentSearchActionKeyword;
}
private List<Result> DirectoryInfoClassSearch(Query query, string querySearch, CancellationToken token)
@ -177,13 +177,13 @@ namespace Flow.Launcher.Plugin.Explorer.Search
private async Task<List<Result>> WindowsIndexFilesAndFoldersSearchAsync(Query query, string querySearchString,
CancellationToken token)
{
var queryConstructor = new QueryConstructor(settings);
var queryConstructor = new QueryConstructor(Settings);
return await IndexSearch.WindowsIndexSearchAsync(
querySearchString,
queryConstructor.CreateQueryHelper,
queryConstructor.QueryForAllFilesAndFolders,
settings.IndexSearchExcludedSubdirectoryPaths,
Settings.IndexSearchExcludedSubdirectoryPaths,
query,
token).ConfigureAwait(false);
}
@ -191,12 +191,12 @@ namespace Flow.Launcher.Plugin.Explorer.Search
private async Task<List<Result>> WindowsIndexTopLevelFolderSearchAsync(Query query, string path,
CancellationToken token)
{
var queryConstructor = new QueryConstructor(settings);
var queryConstructor = new QueryConstructor(Settings);
return await IndexSearch.WindowsIndexSearchAsync(path,
queryConstructor.CreateQueryHelper,
queryConstructor.QueryForTopLevelDirectorySearch,
settings.IndexSearchExcludedSubdirectoryPaths,
Settings.IndexSearchExcludedSubdirectoryPaths,
query,
token).ConfigureAwait(false);
}
@ -205,10 +205,10 @@ namespace Flow.Launcher.Plugin.Explorer.Search
{
var pathToDirectory = FilesFolders.ReturnPreviousDirectoryIfIncompleteString(locationPath);
if (!settings.UseWindowsIndexForDirectorySearch)
if (!Settings.UseWindowsIndexForDirectorySearch)
return false;
if (settings.IndexSearchExcludedSubdirectoryPaths
if (Settings.IndexSearchExcludedSubdirectoryPaths
.Any(x => FilesFolders.ReturnPreviousDirectoryIfIncompleteString(pathToDirectory)
.StartsWith(x.Path, StringComparison.OrdinalIgnoreCase)))
return false;

View file

@ -3,10 +3,12 @@ using Microsoft.Search.Interop;
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
{
@ -107,12 +109,43 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex
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 new List<Result>();
var api = SearchManager.Context.API;
return new List<Result>
{
new Result
{
Title = SearchManager.Context.API.GetTranslation("plugin_explorer_windowsSearchServiceNotRunning"),
SubTitle = SearchManager.Context.API.GetTranslation("plugin_explorer_windowsSearchServiceFix"),
Title = api.GetTranslation("plugin_explorer_windowsSearchServiceNotRunning"),
SubTitle = api.GetTranslation("plugin_explorer_windowsSearchServiceFix"),
Action = c =>
{
SearchManager.Settings.WarnWindowsSearchServiceOff = false;
if (MessageBox.Show(string.Format(api.GetTranslation("plugin_explorer_alternative"), Environment.NewLine),
api.GetTranslation("plugin_explorer_alternative_title"),
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
var pluginsManagerPlugins= api.GetAllPlugins().FirstOrDefault(x => x.Metadata.ID == "9f8f9b14-2518-4907-b211-35ab6290dee7");
api.ChangeQuery(string.Format("{0} install everything", pluginsManagerPlugins.Metadata.ActionKeywords[0]));
}
else
{
// Clears the warning message because same query string will not alter the displayed result list
api.ChangeQuery(string.Empty);
api.ChangeQuery(query.RawQuery);
}
var mainWindow = Application.Current.MainWindow;
mainWindow.Visibility = Visibility.Visible;
mainWindow.Focus();
return false;
},
IcoPath = Constants.ExplorerIconImagePath
}
};

View file

@ -1,4 +1,4 @@
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption;
using System;
@ -33,6 +33,8 @@ namespace Flow.Launcher.Plugin.Explorer
public bool IndexOnlySearchKeywordEnabled { get; set; }
public bool WarnWindowsSearchServiceOff { get; set; } = true;
internal enum ActionKeyword
{
SearchActionKeyword,