mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
code quality
This commit is contained in:
parent
50f5e850dd
commit
545c4208d9
1 changed files with 29 additions and 43 deletions
|
|
@ -40,9 +40,7 @@ namespace Flow.Launcher.ViewModel
|
|||
private Query _lastQuery;
|
||||
private bool _previousIsHomeQuery;
|
||||
private string _queryTextBeforeLeaveResults;
|
||||
|
||||
private string
|
||||
_ignoredQueryText; // Used to ignore query text change when switching between context menu and query results
|
||||
private string _ignoredQueryText; // Used to ignore query text change when switching between context menu and query results
|
||||
|
||||
private readonly FlowLauncherJsonStorage<History> _historyStorage;
|
||||
private readonly FlowLauncherJsonStorage<UserSelectedRecord> _userSelectedRecordStorage;
|
||||
|
|
@ -156,7 +154,6 @@ namespace Flow.Launcher.ViewModel
|
|||
_userSelectedRecordStorage = new FlowLauncherJsonStorage<UserSelectedRecord>();
|
||||
_topMostRecord = new FlowLauncherJsonStorageTopMostRecord();
|
||||
|
||||
|
||||
_history = _historyStorage.Load();
|
||||
_userSelectedRecord = _userSelectedRecordStorage.Load();
|
||||
|
||||
|
|
@ -244,16 +241,14 @@ namespace Flow.Launcher.ViewModel
|
|||
// Indicate if to clear existing results so to show only ones from plugins with action keywords
|
||||
var query = item.Query;
|
||||
var currentIsHomeQuery = query.IsHomeQuery;
|
||||
var shouldClearExistingResults =
|
||||
ShouldClearExistingResultsForQuery(query, currentIsHomeQuery);
|
||||
var shouldClearExistingResults = ShouldClearExistingResultsForQuery(query, currentIsHomeQuery);
|
||||
_lastQuery = item.Query;
|
||||
_previousIsHomeQuery = currentIsHomeQuery;
|
||||
|
||||
// If the queue already has the item, we need to pass the shouldClearExistingResults flag
|
||||
if (queue.TryGetValue(item.ID, out var existingItem))
|
||||
{
|
||||
item.ShouldClearExistingResults = shouldClearExistingResults ||
|
||||
existingItem.ShouldClearExistingResults;
|
||||
item.ShouldClearExistingResults = shouldClearExistingResults || existingItem.ShouldClearExistingResults;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -324,7 +319,7 @@ namespace Flow.Launcher.ViewModel
|
|||
App.API.LogDebug(ClassName, $"Update results for plugin <{pair.Metadata.Name}>");
|
||||
|
||||
if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(resultsCopy, pair.Metadata, e.Query,
|
||||
token)))
|
||||
token)))
|
||||
{
|
||||
App.API.LogError(ClassName, "Unable to add item to Result Update Queue");
|
||||
}
|
||||
|
|
@ -427,8 +422,7 @@ namespace Flow.Launcher.ViewModel
|
|||
if (result is DialogJumpResult dialogJumpResult)
|
||||
{
|
||||
Win32Helper.SetForegroundWindow(DialogWindowHandle);
|
||||
_ = Task.Run(() =>
|
||||
DialogJump.JumpToPathAsync(DialogWindowHandle, dialogJumpResult.DialogJumpPath));
|
||||
_ = Task.Run(() => DialogJump.JumpToPathAsync(DialogWindowHandle, dialogJumpResult.DialogJumpPath));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -553,8 +547,7 @@ namespace Flow.Launcher.ViewModel
|
|||
}
|
||||
}
|
||||
|
||||
private static IReadOnlyList<Result> DeepCloneResults(IReadOnlyList<Result> results, bool isDialogJump,
|
||||
CancellationToken token = default)
|
||||
private static IReadOnlyList<Result> DeepCloneResults(IReadOnlyList<Result> results, bool isDialogJump, CancellationToken token = default)
|
||||
{
|
||||
var resultsCopy = new List<Result>();
|
||||
|
||||
|
|
@ -578,7 +571,6 @@ namespace Flow.Launcher.ViewModel
|
|||
resultsCopy.Add(resultCopy);
|
||||
}
|
||||
}
|
||||
|
||||
return resultsCopy;
|
||||
}
|
||||
|
||||
|
|
@ -628,9 +620,8 @@ namespace Flow.Launcher.ViewModel
|
|||
var historyItems = _history.GetHistoryItems(Settings);
|
||||
if (QueryResultsSelected() // Results selected
|
||||
&& string.IsNullOrEmpty(QueryText) // No input
|
||||
&& Results.Visibility !=
|
||||
Visibility.Visible // No items in result list, e.g. when home page is off and no query text is entered, therefore the view is collapsed.
|
||||
&& historyItems.Count > 0) // Have history items
|
||||
&& Results.Visibility != Visibility.Visible // No items in result list, e.g. when home page is off and no query text is entered, therefore the view is collapsed.
|
||||
&& historyItems.Count > 0)
|
||||
{
|
||||
lastHistoryIndex = 1;
|
||||
ReverseHistory();
|
||||
|
|
@ -702,7 +693,6 @@ namespace Flow.Launcher.ViewModel
|
|||
public bool GameModeStatus { get; set; } = false;
|
||||
|
||||
private string _queryText;
|
||||
|
||||
public string QueryText
|
||||
{
|
||||
get => _queryText;
|
||||
|
|
@ -864,8 +854,7 @@ namespace Flow.Launcher.ViewModel
|
|||
|
||||
// If we are returning from history and we have not set select item yet,
|
||||
// we need to clear the preview selected item
|
||||
if (isReturningFromHistory && _selectedItemFromQueryResults.HasValue &&
|
||||
(!_selectedItemFromQueryResults.Value))
|
||||
if (isReturningFromHistory && _selectedItemFromQueryResults.HasValue && (!_selectedItemFromQueryResults.Value))
|
||||
{
|
||||
PreviewSelectedItem = null;
|
||||
}
|
||||
|
|
@ -883,7 +872,6 @@ namespace Flow.Launcher.ViewModel
|
|||
ContextMenu.Visibility = Visibility.Visible;
|
||||
History.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
_queryTextBeforeLeaveResults = QueryText;
|
||||
|
||||
// Because of Fody's optimization
|
||||
|
|
@ -899,8 +887,7 @@ namespace Flow.Launcher.ViewModel
|
|||
{
|
||||
// If we are returning from query results and we have not set select item yet,
|
||||
// we need to clear the preview selected item
|
||||
if (isReturningFromQueryResults && _selectedItemFromQueryResults.HasValue &&
|
||||
_selectedItemFromQueryResults.Value)
|
||||
if (isReturningFromQueryResults && _selectedItemFromQueryResults.HasValue && _selectedItemFromQueryResults.Value)
|
||||
{
|
||||
PreviewSelectedItem = null;
|
||||
}
|
||||
|
|
@ -910,9 +897,7 @@ namespace Flow.Launcher.ViewModel
|
|||
}
|
||||
|
||||
public Visibility ShowCustomizedPreview
|
||||
=> InternalPreviewVisible && PreviewSelectedItem?.Result.PreviewPanel != null
|
||||
? Visibility.Visible
|
||||
: Visibility.Collapsed;
|
||||
=> InternalPreviewVisible && PreviewSelectedItem?.Result.PreviewPanel != null ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
public UserControl CustomizedPreviewControl
|
||||
=> ShowCustomizedPreview == Visibility.Visible ? PreviewSelectedItem?.Result.PreviewPanel.Value : null;
|
||||
|
|
@ -933,7 +918,6 @@ namespace Flow.Launcher.ViewModel
|
|||
public double SearchIconOpacity { get; set; } = 1;
|
||||
|
||||
private string _placeholderText;
|
||||
|
||||
public string PlaceholderText
|
||||
{
|
||||
get => string.IsNullOrEmpty(_placeholderText) ? Localize.queryTextBoxPlaceholder() : _placeholderText;
|
||||
|
|
@ -1032,7 +1016,6 @@ namespace Flow.Launcher.ViewModel
|
|||
private bool? _selectedItemFromQueryResults;
|
||||
|
||||
private ResultViewModel _previewSelectedItem;
|
||||
|
||||
public ResultViewModel PreviewSelectedItem
|
||||
{
|
||||
get => _previewSelectedItem;
|
||||
|
|
@ -1053,8 +1036,7 @@ namespace Flow.Launcher.ViewModel
|
|||
if (ResultAreaColumn == ResultAreaColumnPreviewHidden)
|
||||
return false;
|
||||
#if DEBUG
|
||||
throw new NotImplementedException(
|
||||
"ResultAreaColumn should match ResultAreaColumnPreviewShown/ResultAreaColumnPreviewHidden value");
|
||||
throw new NotImplementedException("ResultAreaColumn should match ResultAreaColumnPreviewShown/ResultAreaColumnPreviewHidden value");
|
||||
#else
|
||||
App.API.LogError(ClassName, "ResultAreaColumnPreviewHidden/ResultAreaColumnPreviewShown int value not implemented", "InternalPreviewVisible");
|
||||
return false;
|
||||
|
|
@ -1189,7 +1171,6 @@ namespace Flow.Launcher.ViewModel
|
|||
await CloseExternalPreviewAsync();
|
||||
ShowInternalPreview();
|
||||
}
|
||||
|
||||
break;
|
||||
case false
|
||||
when InternalPreviewVisible:
|
||||
|
|
@ -1278,7 +1259,10 @@ namespace Flow.Launcher.ViewModel
|
|||
List<Result> results;
|
||||
if (selected.PluginID == null) // SelectedItem from history in home page.
|
||||
{
|
||||
results = new() { ContextMenuTopMost(selected) };
|
||||
results = new()
|
||||
{
|
||||
ContextMenuTopMost(selected)
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1290,15 +1274,16 @@ namespace Flow.Launcher.ViewModel
|
|||
if (!string.IsNullOrEmpty(query))
|
||||
{
|
||||
var filtered = results.Select(x => x.Clone()).Where
|
||||
(r =>
|
||||
{
|
||||
var match = App.API.FuzzySearch(query, r.Title);
|
||||
if (!match.IsSearchPrecisionScoreMet())
|
||||
{
|
||||
match = App.API.FuzzySearch(query, r.SubTitle);
|
||||
}
|
||||
(
|
||||
r =>
|
||||
{
|
||||
var match = App.API.FuzzySearch(query, r.Title);
|
||||
if (!match.IsSearchPrecisionScoreMet())
|
||||
{
|
||||
match = App.API.FuzzySearch(query, r.SubTitle);
|
||||
}
|
||||
|
||||
if (!match.IsSearchPrecisionScoreMet()) return false;
|
||||
if (!match.IsSearchPrecisionScoreMet()) return false;
|
||||
|
||||
r.Score = match.Score;
|
||||
return true;
|
||||
|
|
@ -1325,9 +1310,10 @@ namespace Flow.Launcher.ViewModel
|
|||
if (!string.IsNullOrEmpty(query))
|
||||
{
|
||||
var filtered = results.Where
|
||||
(r => App.API.FuzzySearch(query, r.Title).IsSearchPrecisionScoreMet() ||
|
||||
App.API.FuzzySearch(query, r.SubTitle).IsSearchPrecisionScoreMet()
|
||||
).ToList();
|
||||
(
|
||||
r => App.API.FuzzySearch(query, r.Title).IsSearchPrecisionScoreMet() ||
|
||||
App.API.FuzzySearch(query, r.SubTitle).IsSearchPrecisionScoreMet()
|
||||
).ToList();
|
||||
History.AddResults(filtered, id);
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in a new issue