Drive Detection Indexer warning refinement (#5221)

* show results always and conditionally show warning

* changed test logic to show warning when expected

* renamed unit test
This commit is contained in:
Alekhya
2020-07-24 17:45:07 -07:00
committed by GitHub
parent 563fb3ff5c
commit 025f2507f4
3 changed files with 83 additions and 85 deletions

View File

@@ -18,10 +18,10 @@ namespace Microsoft.Plugin.Indexer.DriveDetection
GetEnhancedModeStatus(); GetEnhancedModeStatus();
} }
// To display the results if either enhanced mode is on or if the disable drive detection checkbox is checked // To display the warning when Enhanced mode is disabled and the Disable Drive detection check box in settings is unchecked
public bool DisplayResults() public bool DisplayWarning()
{ {
return IsDriveDetectionWarningCheckBoxSelected || IsEnhancedModeEnabled; return !(IsDriveDetectionWarningCheckBoxSelected || IsEnhancedModeEnabled);
} }
// To look up the registry entry for // To look up the registry entry for

View File

@@ -52,103 +52,101 @@ namespace Microsoft.Plugin.Indexer
{ {
var results = new List<Result>(); var results = new List<Result>();
if (_driveDetection.DisplayResults()) if (!string.IsNullOrEmpty(query.Search))
{ {
if (!string.IsNullOrEmpty(query.Search)) var searchQuery = query.Search;
if (_settings.MaxSearchCount <= 0)
{ {
var searchQuery = query.Search; _settings.MaxSearchCount = 50;
if (_settings.MaxSearchCount <= 0) }
{
_settings.MaxSearchCount = 50;
}
var regexMatch = Regex.Match(searchQuery, ReservedStringPattern); var regexMatch = Regex.Match(searchQuery, ReservedStringPattern);
if (!regexMatch.Success) if (!regexMatch.Success)
{
try
{ {
try if(_driveDetection.DisplayWarning())
{ {
var searchResultsList = _api.Search(searchQuery, maxCount: _settings.MaxSearchCount).ToList(); results.Add(new Result
foreach (var searchResult in searchResultsList)
{ {
var path = searchResult.Path; Title = _context.API.GetTranslation("Microsoft_plugin_indexer_drivedetectionwarning"),
var toolTipTitle = string.Format("{0} : {1}", _context.API.GetTranslation("Microsoft_plugin_indexer_name"), searchResult.Title); SubTitle = _context.API.GetTranslation("Microsoft_plugin_indexer_disable_warning_in_settings"),
var toolTipText = string.Format("{0} : {1}", _context.API.GetTranslation("Microsoft_plugin_indexer_path"), path); IcoPath = WarningIconPath,
string workingDir = null; Action = e =>
if (_settings.UseLocationAsWorkingDir)
workingDir = Path.GetDirectoryName(path);
Result r = new Result();
r.Title = searchResult.Title;
r.SubTitle = "Search: " + path;
r.IcoPath = path;
r.ToolTipData = new ToolTipData(toolTipTitle, toolTipText);
r.Action = c =>
{ {
bool hide;
try try
{ {
Process.Start(new ProcessStartInfo Process.Start(GetWindowsSearchSettingsProcessInfo());
{
FileName = path,
UseShellExecute = true,
WorkingDirectory = workingDir
});
hide = true;
} }
catch (Win32Exception) catch (Exception ex)
{ {
var name = $"Plugin: {_context.CurrentPluginMetadata.Name}"; Log.Exception("Microsoft.Plugin.Indexer", $"Unable to launch Windows Search Settings: {ex.Message}", ex, "Query");
var msg = "Can't Open this file";
_context.API.ShowMsg(name, msg, string.Empty);
hide = false;
} }
return hide; return true;
};
r.ContextData = searchResult;
//If the result is a directory, then it's display should show a directory.
if (Directory.Exists(path))
{
r.QueryTextDisplay = path;
} }
});
}
results.Add(r); var searchResultsList = _api.Search(searchQuery, maxCount: _settings.MaxSearchCount).ToList();
foreach (var searchResult in searchResultsList)
{
var path = searchResult.Path;
var toolTipTitle = string.Format("{0} : {1}", _context.API.GetTranslation("Microsoft_plugin_indexer_name"), searchResult.Title);
var toolTipText = string.Format("{0} : {1}", _context.API.GetTranslation("Microsoft_plugin_indexer_path"), path);
string workingDir = null;
if (_settings.UseLocationAsWorkingDir)
workingDir = Path.GetDirectoryName(path);
Result r = new Result();
r.Title = searchResult.Title;
r.SubTitle = "Search: " + path;
r.IcoPath = path;
r.ToolTipData = new ToolTipData(toolTipTitle, toolTipText);
r.Action = c =>
{
bool hide;
try
{
Process.Start(new ProcessStartInfo
{
FileName = path,
UseShellExecute = true,
WorkingDirectory = workingDir
});
hide = true;
}
catch (Win32Exception)
{
var name = $"Plugin: {_context.CurrentPluginMetadata.Name}";
var msg = "Can't Open this file";
_context.API.ShowMsg(name, msg, string.Empty);
hide = false;
}
return hide;
};
r.ContextData = searchResult;
//If the result is a directory, then it's display should show a directory.
if (Directory.Exists(path))
{
r.QueryTextDisplay = path;
} }
results.Add(r);
} }
catch (InvalidOperationException) }
{ catch (InvalidOperationException)
//The connection has closed, internal error of ExecuteReader() {
//Not showing this exception to the users //The connection has closed, internal error of ExecuteReader()
} //Not showing this exception to the users
catch (Exception ex) }
{ catch (Exception ex)
Log.Info(ex.ToString()); {
} Log.Info(ex.ToString());
} }
} }
} }
else
{
results.Add(new Result
{
Title = _context.API.GetTranslation("Microsoft_plugin_indexer_drivedetectionwarning"),
SubTitle = _context.API.GetTranslation("Microsoft_plugin_indexer_disable_warning_in_settings"),
IcoPath = WarningIconPath,
Action = e =>
{
try
{
Process.Start(GetWindowsSearchSettingsProcessInfo());
}
catch (Exception ex)
{
Log.Exception("Microsoft.Plugin.Indexer", $"Unable to launch Windows Search Settings: {ex.Message}", ex, "Query");
}
return true;
}
});
}
return results; return results;
} }

View File

@@ -299,11 +299,11 @@ namespace Wox.Test.Plugins
mockapi.Verify(m => m.GetTranslation("Microsoft_plugin_indexer_open_in_console"), Times.Once()); mockapi.Verify(m => m.GetTranslation("Microsoft_plugin_indexer_open_in_console"), Times.Once());
} }
[TestCase(0, false, ExpectedResult = false)] [TestCase(0, false, ExpectedResult = true)]
[TestCase(0, true, ExpectedResult = true)] [TestCase(0, true, ExpectedResult = false)]
[TestCase(1, false, ExpectedResult = true)] [TestCase(1, false, ExpectedResult = false)]
[TestCase(1, true, ExpectedResult = true)] [TestCase(1, true, ExpectedResult = false)]
public bool DriveDetection_MustDisplayResults_WhenEnhancedModeIsOnOrWhenWarningIsDisabled(int enhancedModeStatus, bool disableWarningCheckBoxStatus) public bool DriveDetection_MustDisplayWarning_WhenEnhancedModeIsOffAndWhenWarningIsNotDisabled(int enhancedModeStatus, bool disableWarningCheckBoxStatus)
{ {
// Arrange // Arrange
var mockRegistry = new Mock<IRegistryWrapper>(); var mockRegistry = new Mock<IRegistryWrapper>();
@@ -313,7 +313,7 @@ namespace Wox.Test.Plugins
_driveDetection.IsDriveDetectionWarningCheckBoxSelected = disableWarningCheckBoxStatus; _driveDetection.IsDriveDetectionWarningCheckBoxSelected = disableWarningCheckBoxStatus;
// Act & Assert // Act & Assert
return _driveDetection.DisplayResults(); return _driveDetection.DisplayWarning();
} }
} }