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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 85 deletions

View file

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

View file

@ -52,102 +52,100 @@ namespace Microsoft.Plugin.Indexer
{
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;
if (_settings.MaxSearchCount <= 0)
{
_settings.MaxSearchCount = 50;
}
_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();
foreach (var searchResult in searchResultsList)
results.Add(new Result
{
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 =>
Title = _context.API.GetTranslation("Microsoft_plugin_indexer_drivedetectionwarning"),
SubTitle = _context.API.GetTranslation("Microsoft_plugin_indexer_disable_warning_in_settings"),
IcoPath = WarningIconPath,
Action = e =>
{
bool hide;
try
{
Process.Start(new ProcessStartInfo
{
FileName = path,
UseShellExecute = true,
WorkingDirectory = workingDir
});
hide = true;
Process.Start(GetWindowsSearchSettingsProcessInfo());
}
catch (Win32Exception)
catch (Exception ex)
{
var name = $"Plugin: {_context.CurrentPluginMetadata.Name}";
var msg = "Can't Open this file";
_context.API.ShowMsg(name, msg, string.Empty);
hide = false;
Log.Exception("Microsoft.Plugin.Indexer", $"Unable to launch Windows Search Settings: {ex.Message}", ex, "Query");
}
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;
return true;
}
});
}
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;
}
}
catch (InvalidOperationException)
{
//The connection has closed, internal error of ExecuteReader()
//Not showing this exception to the users
}
catch (Exception ex)
{
Log.Info(ex.ToString());
results.Add(r);
}
}
}
}
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 =>
catch (InvalidOperationException)
{
try
{
Process.Start(GetWindowsSearchSettingsProcessInfo());
}
catch (Exception ex)
{
Log.Exception("Microsoft.Plugin.Indexer", $"Unable to launch Windows Search Settings: {ex.Message}", ex, "Query");
}
return true;
//The connection has closed, internal error of ExecuteReader()
//Not showing this exception to the users
}
});
catch (Exception ex)
{
Log.Info(ex.ToString());
}
}
}
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());
}
[TestCase(0, false, ExpectedResult = false)]
[TestCase(0, true, ExpectedResult = true)]
[TestCase(1, false, ExpectedResult = true)]
[TestCase(1, true, ExpectedResult = true)]
public bool DriveDetection_MustDisplayResults_WhenEnhancedModeIsOnOrWhenWarningIsDisabled(int enhancedModeStatus, bool disableWarningCheckBoxStatus)
[TestCase(0, false, ExpectedResult = true)]
[TestCase(0, true, ExpectedResult = false)]
[TestCase(1, false, ExpectedResult = false)]
[TestCase(1, true, ExpectedResult = false)]
public bool DriveDetection_MustDisplayWarning_WhenEnhancedModeIsOffAndWhenWarningIsNotDisabled(int enhancedModeStatus, bool disableWarningCheckBoxStatus)
{
// Arrange
var mockRegistry = new Mock<IRegistryWrapper>();
@ -313,7 +313,7 @@ namespace Wox.Test.Plugins
_driveDetection.IsDriveDetectionWarningCheckBoxSelected = disableWarningCheckBoxStatus;
// Act & Assert
return _driveDetection.DisplayResults();
return _driveDetection.DisplayWarning();
}
}